1 ; RUN: opt -S -loop-reroll %s | FileCheck %s
2 target triple = "aarch64--linux-gnu"
4 define void @test(i32 %n, float* %arrayidx200, float* %arrayidx164, float* %arrayidx172) {
6 %rem.i = srem i32 %n, 4
7 %t22 = load float, float* %arrayidx172, align 4
8 %cmp.9 = icmp eq i32 %n, 0
9 %t7 = sext i32 %n to i64
10 br i1 %cmp.9, label %while.end, label %while.body.preheader
16 ;CHECK-LABEL: while.body:
17 ;CHECK-NEXT: %indvar = phi i64 [ %indvar.next, %while.body ], [ 0, %while.body.preheader ]
18 ;CHECK-NEXT: %arrayidx62.i = getelementptr inbounds float, float* %arrayidx200, i64 %indvar
19 ;CHECK-NEXT: %t1 = load float, float* %arrayidx62.i, align 4
20 ;CHECK-NEXT: %arrayidx64.i = getelementptr inbounds float, float* %arrayidx164, i64 %indvar
21 ;CHECK-NEXT: %t2 = load float, float* %arrayidx64.i, align 4
22 ;CHECK-NEXT: %mul65.i = fmul fast float %t2, %t22
23 ;CHECK-NEXT: %add66.i = fadd fast float %mul65.i, %t1
24 ;CHECK-NEXT: store float %add66.i, float* %arrayidx62.i, align 4
25 ;CHECK-NEXT: %indvar.next = add i64 %indvar, 1
26 ;CHECK-NEXT: %exitcond = icmp eq i64 %indvar, %{{[0-9]+}}
27 ;CHECK-NEXT: br i1 %exitcond, label %while.end.loopexit, label %while.body
29 %indvars.iv.i423 = phi i64 [ %indvars.iv.next.i424, %while.body ], [ 0, %while.body.preheader ]
30 %i.22.i = phi i32 [ %add103.i, %while.body ], [ %rem.i, %while.body.preheader ]
31 %arrayidx62.i = getelementptr inbounds float, float* %arrayidx200, i64 %indvars.iv.i423
32 %t1 = load float, float* %arrayidx62.i, align 4
33 %arrayidx64.i = getelementptr inbounds float, float* %arrayidx164, i64 %indvars.iv.i423
34 %t2 = load float, float* %arrayidx64.i, align 4
35 %mul65.i = fmul fast float %t2, %t22
36 %add66.i = fadd fast float %mul65.i, %t1
37 store float %add66.i, float* %arrayidx62.i, align 4
38 %t3 = add nsw i64 %indvars.iv.i423, 1
39 %arrayidx71.i = getelementptr inbounds float, float* %arrayidx200, i64 %t3
40 %t4 = load float, float* %arrayidx71.i, align 4
41 %arrayidx74.i = getelementptr inbounds float, float* %arrayidx164, i64 %t3
42 %t5 = load float, float* %arrayidx74.i, align 4
43 %mul75.i = fmul fast float %t5, %t22
44 %add76.i = fadd fast float %mul75.i, %t4
45 store float %add76.i, float* %arrayidx71.i, align 4
46 %add103.i = add nsw i32 %i.22.i, 2
47 %t6 = sext i32 %add103.i to i64
48 %cmp58.i = icmp slt i64 %t6, %t7
49 %indvars.iv.next.i424 = add i64 %indvars.iv.i423, 2
50 br i1 %cmp58.i, label %while.body, label %while.end.loopexit
59 ; Function Attrs: noinline norecurse nounwind
60 define i32 @test2(i64 %n, i32* nocapture %x, i32* nocapture readonly %y) {
62 %cmp18 = icmp sgt i64 %n, 0
63 br i1 %cmp18, label %for.body.preheader, label %for.end
65 for.body.preheader: ; preds = %entry
68 for.body: ; preds = %for.body.preheader, %for.body
70 ;CHECK-LABEL: for.body:
71 ;CHECK-NEXT: %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %for.body.preheader ]
72 ;CHECK-NEXT: %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvar
73 ;CHECK-NEXT: [[T1:%[0-9]+]] = load i32, i32* %arrayidx, align 4
74 ;CHECK-NEXT: %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvar
75 ;CHECK-NEXT: store i32 [[T1]], i32* %arrayidx3, align 4
76 ;CHECK-NEXT: %indvar.next = add i64 %indvar, 1
77 ;CHECK-NEXT: %exitcond = icmp eq i64 %indvar, %{{[0-9]+}}
78 ;CHECK-NEXT: br i1 %exitcond, label %for.end.loopexit, label %for.body
80 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
81 %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvars.iv
82 %0 = load i32, i32* %arrayidx, align 4
83 %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
84 store i32 %0, i32* %arrayidx3, align 4
85 %1 = or i64 %indvars.iv, 1
86 %arrayidx5 = getelementptr inbounds i32, i32* %y, i64 %1
87 %2 = load i32, i32* %arrayidx5, align 4
88 %arrayidx8 = getelementptr inbounds i32, i32* %x, i64 %1
89 store i32 %2, i32* %arrayidx8, align 4
90 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
91 %cmp = icmp slt i64 %indvars.iv.next, %n
92 br i1 %cmp, label %for.body, label %for.end.loopexit
94 for.end.loopexit: ; preds = %for.body
97 for.end: ; preds = %for.end.loopexit, %entry
101 ; Function Attrs: noinline norecurse nounwind
102 define i32 @test3(i32 %n, i32* nocapture %x, i32* nocapture readonly %y) {
104 %cmp21 = icmp sgt i32 %n, 0
105 br i1 %cmp21, label %for.body.preheader, label %for.end
107 for.body.preheader: ; preds = %entry
110 for.body: ; preds = %for.body.preheader, %for.body
112 ;CHECK-LABEL: for.body:
113 ;CHECK: %add12 = add i8 %i.022, 2
114 ;CHECK-NEXT: %conv = sext i8 %add12 to i32
115 ;CHECK-NEXT: %cmp = icmp slt i32 %conv, %n
116 ;CHECK-NEXT: br i1 %cmp, label %for.body, label %for.end.loopexit
118 %conv23 = phi i32 [ %conv, %for.body ], [ 0, %for.body.preheader ]
119 %i.022 = phi i8 [ %add12, %for.body ], [ 0, %for.body.preheader ]
120 %idxprom = sext i8 %i.022 to i64
121 %arrayidx = getelementptr inbounds i32, i32* %y, i64 %idxprom
122 %0 = load i32, i32* %arrayidx, align 4
123 %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %idxprom
124 store i32 %0, i32* %arrayidx3, align 4
125 %add = or i32 %conv23, 1
126 %idxprom5 = sext i32 %add to i64
127 %arrayidx6 = getelementptr inbounds i32, i32* %y, i64 %idxprom5
128 %1 = load i32, i32* %arrayidx6, align 4
129 %arrayidx10 = getelementptr inbounds i32, i32* %x, i64 %idxprom5
130 store i32 %1, i32* %arrayidx10, align 4
131 %add12 = add i8 %i.022, 2
132 %conv = sext i8 %add12 to i32
133 %cmp = icmp slt i32 %conv, %n
134 br i1 %cmp, label %for.body, label %for.end.loopexit
136 for.end.loopexit: ; preds = %for.body
139 for.end: ; preds = %for.end.loopexit, %entry
143 ; Function Attrs: noinline norecurse nounwind
144 define i32 @test4(i64 %n, i32* nocapture %x, i32* nocapture readonly %y) {
146 %cmp18 = icmp eq i64 %n, 0
147 br i1 %cmp18, label %for.end, label %for.body.preheader
149 for.body.preheader: ; preds = %entry
152 for.body: ; preds = %for.body.preheader, %for.body
154 ;CHECK-LABEL: for.body:
155 ;CHECK-NEXT: %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %for.body.preheader ]
156 ;CHECK-NEXT: %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvar
157 ;CHECK-NEXT: [[T1:%[0-9]+]] = load i32, i32* %arrayidx, align 4
158 ;CHECK-NEXT: %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvar
159 ;CHECK-NEXT: store i32 [[T1]], i32* %arrayidx3, align 4
160 ;CHECK-NEXT: %indvar.next = add i64 %indvar, 1
161 ;CHECK-NEXT: %exitcond = icmp eq i64 %indvar, %{{[0-9]+}}
162 ;CHECK-NEXT: br i1 %exitcond, label %for.end.loopexit, label %for.body
164 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
165 %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvars.iv
166 %0 = load i32, i32* %arrayidx, align 4
167 %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
168 store i32 %0, i32* %arrayidx3, align 4
169 %1 = or i64 %indvars.iv, 1
170 %arrayidx5 = getelementptr inbounds i32, i32* %y, i64 %1
171 %2 = load i32, i32* %arrayidx5, align 4
172 %arrayidx8 = getelementptr inbounds i32, i32* %x, i64 %1
173 store i32 %2, i32* %arrayidx8, align 4
174 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
175 %cmp = icmp ult i64 %indvars.iv.next, %n
176 br i1 %cmp, label %for.body, label %for.end.loopexit
178 for.end.loopexit: ; preds = %for.body
181 for.end: ; preds = %for.end.loopexit, %entry