1 ; RUN: opt -S -loop-reroll %s | FileCheck %s
2 declare i32 @goo(i32, i32)
4 @buf = external global i8*
5 @aaa = global [16 x i8] c"\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\10", align 1
7 define i32 @test1(i32 %len) {
12 ;CHECK-LABEL: while.body:
13 ;CHECK-NEXT: %indvar = phi i64 [ %indvar.next, %while.body ], [ 0, %entry ]
14 ;CHECK-NEXT: %sum44.020 = phi i64 [ 0, %entry ], [ %add, %while.body ]
15 ;CHECK-NEXT: %0 = trunc i64 %indvar to i32
16 ;CHECK-NEXT: %scevgep = getelementptr [16 x i8], [16 x i8]* @aaa, i64 0, i64 %indvar
17 ;CHECK-NEXT: [[T2:%[0-9]+]] = load i8, i8* %scevgep, align 1
18 ;CHECK-NEXT: %conv = zext i8 [[T2]] to i64
19 ;CHECK-NEXT: %add = add i64 %conv, %sum44.020
20 ;CHECK-NEXT: %indvar.next = add i64 %indvar, 1
21 ;CHECK-NEXT: %exitcond = icmp eq i32 %0, 15
22 ;CHECK-NEXT: br i1 %exitcond, label %while.end, label %while.body
24 %dec22 = phi i32 [ 4, %entry ], [ %dec, %while.body ]
25 %buf.021 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @aaa, i64 0, i64 0), %entry ], [ %add.ptr, %while.body ]
26 %sum44.020 = phi i64 [ 0, %entry ], [ %add9, %while.body ]
27 %0 = load i8, i8* %buf.021, align 1
28 %conv = zext i8 %0 to i64
29 %add = add i64 %conv, %sum44.020
30 %arrayidx1 = getelementptr inbounds i8, i8* %buf.021, i64 1
31 %1 = load i8, i8* %arrayidx1, align 1
32 %conv2 = zext i8 %1 to i64
33 %add3 = add i64 %add, %conv2
34 %arrayidx4 = getelementptr inbounds i8, i8* %buf.021, i64 2
35 %2 = load i8, i8* %arrayidx4, align 1
36 %conv5 = zext i8 %2 to i64
37 %add6 = add i64 %add3, %conv5
38 %arrayidx7 = getelementptr inbounds i8, i8* %buf.021, i64 3
39 %3 = load i8, i8* %arrayidx7, align 1
40 %conv8 = zext i8 %3 to i64
41 %add9 = add i64 %add6, %conv8
42 %add.ptr = getelementptr inbounds i8, i8* %buf.021, i64 4
43 %dec = add nsw i32 %dec22, -1
44 %tobool = icmp eq i32 %dec, 0
45 br i1 %tobool, label %while.end, label %while.body
47 while.end: ; preds = %while.body
48 %conv11 = trunc i64 %add9 to i32
49 %call = tail call i32 @goo(i32 0, i32 %conv11)
53 define i32 @test2(i32 %N, i32* nocapture readonly %a, i32 %S) {
55 %cmp.9 = icmp sgt i32 %N, 0
56 br i1 %cmp.9, label %for.body.lr.ph, label %for.cond.cleanup
61 for.cond.for.cond.cleanup_crit_edge:
62 br label %for.cond.cleanup
65 %S.addr.0.lcssa = phi i32 [ %add2, %for.cond.for.cond.cleanup_crit_edge ], [ %S, %entry ]
66 ret i32 %S.addr.0.lcssa
69 ;CHECK-LABEL: for.body:
70 ;CHECK-NEXT: %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %for.body.lr.ph ]
71 ;CHECK-NEXT: %S.addr.011 = phi i32 [ %S, %for.body.lr.ph ], [ %add, %for.body ]
72 ;CHECK-NEXT: %4 = trunc i64 %indvar to i32
73 ;CHECK-NEXT: %scevgep = getelementptr i32, i32* %a, i64 %indvar
74 ;CHECK-NEXT: %5 = load i32, i32* %scevgep, align 4
75 ;CHECK-NEXT: %add = add nsw i32 %5, %S.addr.011
76 ;CHECK-NEXT: %indvar.next = add i64 %indvar, 1
77 ;CHECK-NEXT: %exitcond = icmp eq i32 %4, %3
78 ;CHECK-NEXT: br i1 %exitcond, label %for.cond.for.cond.cleanup_crit_edge, label %for.body
80 %i.012 = phi i32 [ 0, %for.body.lr.ph ], [ %add3, %for.body ]
81 %S.addr.011 = phi i32 [ %S, %for.body.lr.ph ], [ %add2, %for.body ]
82 %a.addr.010 = phi i32* [ %a, %for.body.lr.ph ], [ %incdec.ptr1, %for.body ]
83 %incdec.ptr = getelementptr inbounds i32, i32* %a.addr.010, i64 1
84 %0 = load i32, i32* %a.addr.010, align 4
85 %add = add nsw i32 %0, %S.addr.011
86 %incdec.ptr1 = getelementptr inbounds i32, i32* %a.addr.010, i64 2
87 %1 = load i32, i32* %incdec.ptr, align 4
88 %add2 = add nsw i32 %add, %1
89 %add3 = add nsw i32 %i.012, 2
90 %cmp = icmp slt i32 %add3, %N
91 br i1 %cmp, label %for.body, label %for.cond.for.cond.cleanup_crit_edge
94 define i32 @test3(i32* nocapture readonly %buf, i32 %len) #0 {
96 %cmp10 = icmp sgt i32 %len, 1
97 br i1 %cmp10, label %while.body.preheader, label %while.end
99 while.body.preheader: ; preds = %entry
102 while.body: ; preds = %while.body.preheader, %while.body
103 ;CHECK-LABEL: while.body:
104 ;CHECK-NEXT: %indvar = phi i64 [ %indvar.next, %while.body ], [ 0, %while.body.preheader ]
105 ;CHECK-NEXT: %S.012 = phi i32 [ %add, %while.body ], [ undef, %while.body.preheader ]
106 ;CHECK-NEXT: %4 = trunc i64 %indvar to i32
107 ;CHECK-NEXT: %5 = mul nsw i64 %indvar, -1
108 ;CHECK-NEXT: %scevgep = getelementptr i32, i32* %buf, i64 %5
109 ;CHECK-NEXT: %6 = load i32, i32* %scevgep, align 4
110 ;CHECK-NEXT: %add = add nsw i32 %6, %S.012
111 ;CHECK-NEXT: %indvar.next = add i64 %indvar, 1
112 ;CHECK-NEXT: %exitcond = icmp eq i32 %4, %3
113 ;CHECK-NEXT: br i1 %exitcond, label %while.end.loopexit, label %while.body
115 %i.013 = phi i32 [ %sub, %while.body ], [ %len, %while.body.preheader ]
116 %S.012 = phi i32 [ %add2, %while.body ], [ undef, %while.body.preheader ]
117 %buf.addr.011 = phi i32* [ %add.ptr, %while.body ], [ %buf, %while.body.preheader ]
118 %0 = load i32, i32* %buf.addr.011, align 4
119 %add = add nsw i32 %0, %S.012
120 %arrayidx1 = getelementptr inbounds i32, i32* %buf.addr.011, i64 -1
121 %1 = load i32, i32* %arrayidx1, align 4
122 %add2 = add nsw i32 %add, %1
123 %add.ptr = getelementptr inbounds i32, i32* %buf.addr.011, i64 -2
124 %sub = add nsw i32 %i.013, -2
125 %cmp = icmp sgt i32 %sub, 1
126 br i1 %cmp, label %while.body, label %while.end.loopexit
128 while.end.loopexit: ; preds = %while.body
131 while.end: ; preds = %while.end.loopexit, %entry
132 %S.0.lcssa = phi i32 [ undef, %entry ], [ %add2, %while.end.loopexit ]