1; RUN: opt -S  -loop-reroll   %s | FileCheck %s
2target triple = "aarch64--linux-gnu"
3
4define void @test(i32 %n, float* %arrayidx200, float* %arrayidx164, float* %arrayidx172) {
5entry:
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
11
12while.body.preheader:
13  br label %while.body
14
15while.body:
16;CHECK-LABEL: while.body:
17;CHECK-NEXT:    %indvars.iv.i423 = phi i64 [ %indvars.iv.next.i424, %while.body ], [ 0, %while.body.preheader ]
18;CHECK-NEXT:    [[T1:%[0-9]+]] = trunc i64 %indvars.iv.i423 to i32
19;CHECK-NEXT:    %arrayidx62.i = getelementptr inbounds float, float* %arrayidx200, i64 %indvars.iv.i423
20;CHECK-NEXT:    %t1 = load float, float* %arrayidx62.i, align 4
21;CHECK-NEXT:    %arrayidx64.i = getelementptr inbounds float, float* %arrayidx164, i64 %indvars.iv.i423
22;CHECK-NEXT:    %t2 = load float, float* %arrayidx64.i, align 4
23;CHECK-NEXT:    %mul65.i = fmul fast float %t2, %t22
24;CHECK-NEXT:    %add66.i = fadd fast float %mul65.i, %t1
25;CHECK-NEXT:    store float %add66.i, float* %arrayidx62.i, align 4
26;CHECK-NEXT:    %indvars.iv.next.i424 = add i64 %indvars.iv.i423, 1
27;CHECK-NEXT:    [[T2:%[0-9]+]] = sext i32 [[T1]] to i64
28;CHECK-NEXT:    %exitcond = icmp eq i64 [[T2]], %{{[0-9]+}}
29;CHECK-NEXT:    br i1 %exitcond, label %while.end.loopexit, label %while.body
30
31  %indvars.iv.i423 = phi i64 [ %indvars.iv.next.i424, %while.body ], [ 0, %while.body.preheader ]
32  %i.22.i = phi i32 [ %add103.i, %while.body ], [ %rem.i, %while.body.preheader ]
33  %arrayidx62.i = getelementptr inbounds float, float* %arrayidx200, i64 %indvars.iv.i423
34  %t1 = load float, float* %arrayidx62.i, align 4
35  %arrayidx64.i = getelementptr inbounds float, float* %arrayidx164, i64 %indvars.iv.i423
36  %t2 = load float, float* %arrayidx64.i, align 4
37  %mul65.i = fmul fast float %t2, %t22
38  %add66.i = fadd fast float %mul65.i, %t1
39  store float %add66.i, float* %arrayidx62.i, align 4
40  %t3 = add nsw i64 %indvars.iv.i423, 1
41  %arrayidx71.i = getelementptr inbounds float, float* %arrayidx200, i64 %t3
42  %t4 = load float, float* %arrayidx71.i, align 4
43  %arrayidx74.i = getelementptr inbounds float, float* %arrayidx164, i64 %t3
44  %t5 = load float, float* %arrayidx74.i, align 4
45  %mul75.i = fmul fast float %t5, %t22
46  %add76.i = fadd fast float %mul75.i, %t4
47  store float %add76.i, float* %arrayidx71.i, align 4
48  %add103.i = add nsw i32 %i.22.i, 2
49  %t6 = sext i32 %add103.i to i64
50  %cmp58.i = icmp slt i64 %t6, %t7
51  %indvars.iv.next.i424 = add i64 %indvars.iv.i423, 2
52  br i1 %cmp58.i, label %while.body, label %while.end.loopexit
53
54while.end.loopexit:
55  br label %while.end
56
57while.end:
58  ret void
59}
60
61; Function Attrs: noinline norecurse nounwind
62define i32 @test2(i64 %n, i32* nocapture %x, i32* nocapture readonly %y) {
63entry:
64  %cmp18 = icmp sgt i64 %n, 0
65  br i1 %cmp18, label %for.body.preheader, label %for.end
66
67for.body.preheader:                               ; preds = %entry
68  br label %for.body
69
70for.body:                                         ; preds = %for.body.preheader, %for.body
71
72;CHECK:     for.body:
73;CHECK-NEXT:  %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %for.body.preheader ]
74;CHECK-NEXT:  %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvar
75;CHECK-NEXT:  [[T1:%[0-9]+]] = load i32, i32* %arrayidx, align 4
76;CHECK-NEXT:  %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvar
77;CHECK-NEXT:  store i32 [[T1]], i32* %arrayidx3, align 4
78;CHECK-NEXT:  %indvar.next = add i64 %indvar, 1
79;CHECK-NEXT:  %exitcond = icmp eq i64 %indvar, %{{[0-9]+}}
80;CHECK-NEXT:  br i1 %exitcond, label %for.end.loopexit, label %for.body
81
82  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
83  %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvars.iv
84  %0 = load i32, i32* %arrayidx, align 4
85  %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
86  store i32 %0, i32* %arrayidx3, align 4
87  %1 = or i64 %indvars.iv, 1
88  %arrayidx5 = getelementptr inbounds i32, i32* %y, i64 %1
89  %2 = load i32, i32* %arrayidx5, align 4
90  %arrayidx8 = getelementptr inbounds i32, i32* %x, i64 %1
91  store i32 %2, i32* %arrayidx8, align 4
92  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
93  %cmp = icmp slt i64 %indvars.iv.next, %n
94  br i1 %cmp, label %for.body, label %for.end.loopexit
95
96for.end.loopexit:                                 ; preds = %for.body
97  br label %for.end
98
99for.end:                                          ; preds = %for.end.loopexit, %entry
100  ret i32 0
101}
102
103; Function Attrs: noinline norecurse nounwind
104define i32 @test3(i32 %n, i32* nocapture %x, i32* nocapture readonly %y) {
105entry:
106  %cmp21 = icmp sgt i32 %n, 0
107  br i1 %cmp21, label %for.body.preheader, label %for.end
108
109for.body.preheader:                               ; preds = %entry
110  br label %for.body
111
112for.body:                                         ; preds = %for.body.preheader, %for.body
113
114;CHECK:      for.body:
115;CHECK:        %add12 = add i8 %i.022, 2
116;CHECK-NEXT:   %conv = sext i8 %add12 to i32
117;CHECK-NEXT:   %cmp = icmp slt i32 %conv, %n
118;CHECK-NEXT:   br i1 %cmp, label %for.body, label %for.end.loopexit
119
120  %conv23 = phi i32 [ %conv, %for.body ], [ 0, %for.body.preheader ]
121  %i.022 = phi i8 [ %add12, %for.body ], [ 0, %for.body.preheader ]
122  %idxprom = sext i8 %i.022 to i64
123  %arrayidx = getelementptr inbounds i32, i32* %y, i64 %idxprom
124  %0 = load i32, i32* %arrayidx, align 4
125  %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %idxprom
126  store i32 %0, i32* %arrayidx3, align 4
127  %add = or i32 %conv23, 1
128  %idxprom5 = sext i32 %add to i64
129  %arrayidx6 = getelementptr inbounds i32, i32* %y, i64 %idxprom5
130  %1 = load i32, i32* %arrayidx6, align 4
131  %arrayidx10 = getelementptr inbounds i32, i32* %x, i64 %idxprom5
132  store i32 %1, i32* %arrayidx10, align 4
133  %add12 = add i8 %i.022, 2
134  %conv = sext i8 %add12 to i32
135  %cmp = icmp slt i32 %conv, %n
136  br i1 %cmp, label %for.body, label %for.end.loopexit
137
138for.end.loopexit:                                 ; preds = %for.body
139  br label %for.end
140
141for.end:                                          ; preds = %for.end.loopexit, %entry
142  ret i32 0
143}
144
145; Function Attrs: noinline norecurse nounwind
146define i32 @test4(i64 %n, i32* nocapture %x, i32* nocapture readonly %y) {
147entry:
148  %cmp18 = icmp eq i64 %n, 0
149  br i1 %cmp18, label %for.end, label %for.body.preheader
150
151for.body.preheader:                               ; preds = %entry
152  br label %for.body
153
154for.body:                                         ; preds = %for.body.preheader, %for.body
155
156;CHECK:     for.body:
157;CHECK-NEXT:  %indvar = phi i64 [ %indvar.next, %for.body ], [ 0, %for.body.preheader ]
158;CHECK-NEXT:  %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvar
159;CHECK-NEXT:  [[T1:%[0-9]+]] = load i32, i32* %arrayidx, align 4
160;CHECK-NEXT:  %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvar
161;CHECK-NEXT:  store i32 [[T1]], i32* %arrayidx3, align 4
162;CHECK-NEXT:  %indvar.next = add i64 %indvar, 1
163;CHECK-NEXT:  %exitcond = icmp eq i64 %indvar, %{{[0-9]+}}
164;CHECK-NEXT:  br i1 %exitcond, label %for.end.loopexit, label %for.body
165
166  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
167  %arrayidx = getelementptr inbounds i32, i32* %y, i64 %indvars.iv
168  %0 = load i32, i32* %arrayidx, align 4
169  %arrayidx3 = getelementptr inbounds i32, i32* %x, i64 %indvars.iv
170  store i32 %0, i32* %arrayidx3, align 4
171  %1 = or i64 %indvars.iv, 1
172  %arrayidx5 = getelementptr inbounds i32, i32* %y, i64 %1
173  %2 = load i32, i32* %arrayidx5, align 4
174  %arrayidx8 = getelementptr inbounds i32, i32* %x, i64 %1
175  store i32 %2, i32* %arrayidx8, align 4
176  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
177  %cmp = icmp ult i64 %indvars.iv.next, %n
178  br i1 %cmp, label %for.body, label %for.end.loopexit
179
180for.end.loopexit:                                 ; preds = %for.body
181  br label %for.end
182
183for.end:                                          ; preds = %for.end.loopexit, %entry
184  ret i32 0
185}
186
187