1*cee313d2SEric Christopher; RUN: opt < %s -S -O2 -unroll-runtime=true -unroll-runtime-epilog=true  | FileCheck %s -check-prefix=EPILOG
2*cee313d2SEric Christopher; RUN: opt < %s -S -O2 -unroll-runtime=true -unroll-runtime-epilog=false | FileCheck %s -check-prefix=PROLOG
3*cee313d2SEric Christopher
4*cee313d2SEric Christopher; Check runtime unrolling prologue can be promoted by LICM pass.
5*cee313d2SEric Christopher
6*cee313d2SEric Christopher; EPILOG: entry:
7*cee313d2SEric Christopher; EPILOG: %xtraiter
8*cee313d2SEric Christopher; EPILOG: %lcmp.mod
9*cee313d2SEric Christopher; EPILOG: loop1:
10*cee313d2SEric Christopher; EPILOG: br i1 %lcmp.mod
11*cee313d2SEric Christopher; EPILOG: loop2.epil:
12*cee313d2SEric Christopher
13*cee313d2SEric Christopher; PROLOG: entry:
14*cee313d2SEric Christopher; PROLOG: %xtraiter
15*cee313d2SEric Christopher; PROLOG: %lcmp.mod
16*cee313d2SEric Christopher; PROLOG: loop1:
17*cee313d2SEric Christopher; PROLOG: br i1 %lcmp.mod
18*cee313d2SEric Christopher; PROLOG: loop2.prol:
19*cee313d2SEric Christopher
20*cee313d2SEric Christopherdefine void @unroll(i32 %iter, i32* %addr1, i32* %addr2) nounwind {
21*cee313d2SEric Christopherentry:
22*cee313d2SEric Christopher  br label %loop1
23*cee313d2SEric Christopher
24*cee313d2SEric Christopherloop1:
25*cee313d2SEric Christopher  %iv1 = phi i32 [ 0, %entry ], [ %inc1, %loop1.latch ]
26*cee313d2SEric Christopher  %offset1 = getelementptr i32, i32* %addr1, i32 %iv1
27*cee313d2SEric Christopher  store i32 %iv1, i32* %offset1, align 4
28*cee313d2SEric Christopher  br label %loop2.header
29*cee313d2SEric Christopher
30*cee313d2SEric Christopherloop2.header:
31*cee313d2SEric Christopher  %e = icmp uge i32 %iter, 1
32*cee313d2SEric Christopher  br i1 %e, label %loop2, label %exit2
33*cee313d2SEric Christopher
34*cee313d2SEric Christopherloop2:
35*cee313d2SEric Christopher  %iv2 = phi i32 [ 0, %loop2.header ], [ %inc2, %loop2 ]
36*cee313d2SEric Christopher  %offset2 = getelementptr i32, i32* %addr2, i32 %iv2
37*cee313d2SEric Christopher  store i32 %iv2, i32* %offset2, align 4
38*cee313d2SEric Christopher  %inc2 = add i32 %iv2, 1
39*cee313d2SEric Christopher  %exitcnd2 = icmp uge i32 %inc2, %iter
40*cee313d2SEric Christopher  br i1 %exitcnd2, label %exit2, label %loop2
41*cee313d2SEric Christopher
42*cee313d2SEric Christopherexit2:
43*cee313d2SEric Christopher  br label %loop1.latch
44*cee313d2SEric Christopher
45*cee313d2SEric Christopherloop1.latch:
46*cee313d2SEric Christopher  %inc1 = add i32 %iv1, 1
47*cee313d2SEric Christopher  %exitcnd1 = icmp uge i32 %inc1, 1024
48*cee313d2SEric Christopher  br i1 %exitcnd1, label %exit, label %loop1
49*cee313d2SEric Christopher
50*cee313d2SEric Christopherexit:
51*cee313d2SEric Christopher  ret void
52*cee313d2SEric Christopher}
53