1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -loop-unroll -verify-dom-info | FileCheck %s
7 ; Check that we can peel off iterations that make conditions true.
8 define void @test1(i32 %k) {
10 ; CHECK-NEXT: for.body.lr.ph:
11 ; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
12 ; CHECK: for.body.peel.begin:
13 ; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
14 ; CHECK: for.body.peel:
15 ; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ult i32 0, 2
16 ; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
17 ; CHECK: if.else.peel:
18 ; CHECK-NEXT: call void @f2()
19 ; CHECK-NEXT: br label [[FOR_INC_PEEL:%.*]]
20 ; CHECK: if.then.peel:
21 ; CHECK-NEXT: call void @f1()
22 ; CHECK-NEXT: br label [[FOR_INC_PEEL]]
23 ; CHECK: for.inc.peel:
24 ; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
25 ; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
26 ; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%[^,]*]]
27 ; Verify that MD_loop metadata is dropped.
28 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
29 ; CHECK: for.body.peel.next:
30 ; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
31 ; CHECK: for.body.peel2:
32 ; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ult i32 [[INC_PEEL]], 2
33 ; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
34 ; CHECK: if.else.peel4:
35 ; CHECK-NEXT: call void @f2()
36 ; CHECK-NEXT: br label [[FOR_INC_PEEL6:%.*]]
37 ; CHECK: if.then.peel5:
38 ; CHECK-NEXT: call void @f1()
39 ; CHECK-NEXT: br label [[FOR_INC_PEEL6]]
40 ; CHECK: for.inc.peel6:
41 ; CHECK-NEXT: [[INC_PEEL7:%.*]] = add nsw i32 [[INC_PEEL]], 1
42 ; CHECK-NEXT: [[CMP_PEEL8:%.*]] = icmp slt i32 [[INC_PEEL7]], [[K]]
43 ; CHECK-NEXT: br i1 [[CMP_PEEL8]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
44 ; Verify that MD_loop metadata is dropped.
45 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
46 ; CHECK: for.body.peel.next1:
47 ; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT9:%.*]]
48 ; CHECK: for.body.peel.next9:
49 ; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
50 ; CHECK: for.body.lr.ph.peel.newph:
51 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
53 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL7]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
54 ; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
56 ; CHECK-NEXT: call void @f1()
57 ; CHECK-NEXT: br label [[FOR_INC]]
59 ; CHECK-NEXT: call void @f2()
60 ; CHECK-NEXT: br label [[FOR_INC]]
62 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_05]], 1
63 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
64 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !{{.*}}
65 ; CHECK: for.end.loopexit:
66 ; CHECK-NEXT: br label [[FOR_END]]
68 ; CHECK-NEXT: ret void
74 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
75 %cmp1 = icmp ult i32 %i.05, 2
76 br i1 %cmp1, label %if.then, label %if.else
87 %inc = add nsw i32 %i.05, 1
88 %cmp = icmp slt i32 %inc, %k
89 br i1 %cmp, label %for.body, label %for.end, !llvm.loop !1
97 ; Check we peel off the maximum number of iterations that make conditions true.
98 define void @test2(i32 %k) {
99 ; CHECK-LABEL: @test2(
100 ; CHECK-NEXT: for.body.lr.ph:
101 ; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
102 ; CHECK: for.body.peel.begin:
103 ; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
104 ; CHECK: for.body.peel:
105 ; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ult i32 0, 2
106 ; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
107 ; CHECK: if.else.peel:
108 ; CHECK-NEXT: call void @f2()
109 ; CHECK-NEXT: br label [[IF2_PEEL:%.*]]
110 ; CHECK: if.then.peel:
111 ; CHECK-NEXT: call void @f1()
112 ; CHECK-NEXT: br label [[IF2_PEEL]]
114 ; CHECK-NEXT: [[CMP2_PEEL:%.*]] = icmp ult i32 0, 4
115 ; CHECK-NEXT: br i1 [[CMP2_PEEL]], label [[IF_THEN2_PEEL:%.*]], label [[FOR_INC_PEEL:%.*]]
116 ; CHECK: if.then2.peel:
117 ; CHECK-NEXT: call void @f1()
118 ; CHECK-NEXT: br label [[FOR_INC_PEEL]]
119 ; CHECK: for.inc.peel:
120 ; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
121 ; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
122 ; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%[^,]*]]
123 ; Verify that MD_loop metadata is dropped.
124 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
125 ; CHECK: for.body.peel.next:
126 ; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
127 ; CHECK: for.body.peel2:
128 ; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ult i32 [[INC_PEEL]], 2
129 ; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
130 ; CHECK: if.else.peel4:
131 ; CHECK-NEXT: call void @f2()
132 ; CHECK-NEXT: br label [[IF2_PEEL6:%.*]]
133 ; CHECK: if.then.peel5:
134 ; CHECK-NEXT: call void @f1()
135 ; CHECK-NEXT: br label [[IF2_PEEL6]]
137 ; CHECK-NEXT: [[CMP2_PEEL7:%.*]] = icmp ult i32 [[INC_PEEL]], 4
138 ; CHECK-NEXT: br i1 [[CMP2_PEEL7]], label [[IF_THEN2_PEEL8:%.*]], label [[FOR_INC_PEEL9:%.*]]
139 ; CHECK: if.then2.peel8:
140 ; CHECK-NEXT: call void @f1()
141 ; CHECK-NEXT: br label [[FOR_INC_PEEL9]]
142 ; CHECK: for.inc.peel9:
143 ; CHECK-NEXT: [[INC_PEEL10:%.*]] = add nsw i32 [[INC_PEEL]], 1
144 ; CHECK-NEXT: [[CMP_PEEL11:%.*]] = icmp slt i32 [[INC_PEEL10]], [[K]]
145 ; CHECK-NEXT: br i1 [[CMP_PEEL11]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
146 ; Verify that MD_loop metadata is dropped.
147 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
148 ; CHECK: for.body.peel.next1:
149 ; CHECK-NEXT: br label [[FOR_BODY_PEEL13:%.*]]
150 ; CHECK: for.body.peel13:
151 ; CHECK-NEXT: [[CMP1_PEEL14:%.*]] = icmp ult i32 [[INC_PEEL10]], 2
152 ; CHECK-NEXT: br i1 [[CMP1_PEEL14]], label [[IF_THEN_PEEL16:%.*]], label [[IF_ELSE_PEEL15:%.*]]
153 ; CHECK: if.else.peel15:
154 ; CHECK-NEXT: call void @f2()
155 ; CHECK-NEXT: br label [[IF2_PEEL17:%.*]]
156 ; CHECK: if.then.peel16:
157 ; CHECK-NEXT: call void @f1()
158 ; CHECK-NEXT: br label [[IF2_PEEL17]]
160 ; CHECK-NEXT: [[CMP2_PEEL18:%.*]] = icmp ult i32 [[INC_PEEL10]], 4
161 ; CHECK-NEXT: br i1 [[CMP2_PEEL18]], label [[IF_THEN2_PEEL19:%.*]], label [[FOR_INC_PEEL20:%.*]]
162 ; CHECK: if.then2.peel19:
163 ; CHECK-NEXT: call void @f1()
164 ; CHECK-NEXT: br label [[FOR_INC_PEEL20]]
165 ; CHECK: for.inc.peel20:
166 ; CHECK-NEXT: [[INC_PEEL21:%.*]] = add nsw i32 [[INC_PEEL10]], 1
167 ; CHECK-NEXT: [[CMP_PEEL22:%.*]] = icmp slt i32 [[INC_PEEL21]], [[K]]
168 ; CHECK-NEXT: br i1 [[CMP_PEEL22]], label [[FOR_BODY_PEEL_NEXT12:%.*]], label [[FOR_END]]
169 ; Verify that MD_loop metadata is dropped.
170 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
171 ; CHECK: for.body.peel.next12:
172 ; CHECK-NEXT: br label [[FOR_BODY_PEEL24:%.*]]
173 ; CHECK: for.body.peel24:
174 ; CHECK-NEXT: [[CMP1_PEEL25:%.*]] = icmp ult i32 [[INC_PEEL21]], 2
175 ; CHECK-NEXT: br i1 [[CMP1_PEEL25]], label [[IF_THEN_PEEL27:%.*]], label [[IF_ELSE_PEEL26:%.*]]
176 ; CHECK: if.else.peel26:
177 ; CHECK-NEXT: call void @f2()
178 ; CHECK-NEXT: br label [[IF2_PEEL28:%.*]]
179 ; CHECK: if.then.peel27:
180 ; CHECK-NEXT: call void @f1()
181 ; CHECK-NEXT: br label [[IF2_PEEL28]]
183 ; CHECK-NEXT: [[CMP2_PEEL29:%.*]] = icmp ult i32 [[INC_PEEL21]], 4
184 ; CHECK-NEXT: br i1 [[CMP2_PEEL29]], label [[IF_THEN2_PEEL30:%.*]], label [[FOR_INC_PEEL31:%.*]]
185 ; CHECK: if.then2.peel30:
186 ; CHECK-NEXT: call void @f1()
187 ; CHECK-NEXT: br label [[FOR_INC_PEEL31]]
188 ; CHECK: for.inc.peel31:
189 ; CHECK-NEXT: [[INC_PEEL32:%.*]] = add nsw i32 [[INC_PEEL21]], 1
190 ; CHECK-NEXT: [[CMP_PEEL33:%.*]] = icmp slt i32 [[INC_PEEL32]], [[K]]
191 ; CHECK-NEXT: br i1 [[CMP_PEEL33]], label [[FOR_BODY_PEEL_NEXT23:%.*]], label [[FOR_END]]
192 ; Verify that MD_loop metadata is dropped.
193 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
194 ; CHECK: for.body.peel.next23:
195 ; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT34:%.*]]
196 ; CHECK: for.body.peel.next34:
197 ; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
198 ; CHECK: for.body.lr.ph.peel.newph:
199 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
201 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL32]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
202 ; CHECK-NEXT: br i1 false, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
204 ; CHECK-NEXT: call void @f1()
205 ; CHECK-NEXT: br label [[IF2:%.*]]
207 ; CHECK-NEXT: call void @f2()
208 ; CHECK-NEXT: br label [[IF2]]
210 ; CHECK-NEXT: br i1 false, label [[IF_THEN2:%.*]], label [[FOR_INC]]
212 ; CHECK-NEXT: call void @f1()
213 ; CHECK-NEXT: br label [[FOR_INC]]
215 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_05]], 1
216 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
217 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !{{.*}}
218 ; CHECK: for.end.loopexit:
219 ; CHECK-NEXT: br label [[FOR_END]]
221 ; CHECK-NEXT: ret void
227 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
228 %cmp1 = icmp ult i32 %i.05, 2
229 br i1 %cmp1, label %if.then, label %if.else
240 %cmp2 = icmp ult i32 %i.05, 4
241 br i1 %cmp2, label %if.then2, label %for.inc
248 %inc = add nsw i32 %i.05, 1
249 %cmp = icmp slt i32 %inc, %k
250 br i1 %cmp, label %for.body, label %for.end, !llvm.loop !2
258 ; Check that we can peel off iterations that make a condition false.
259 define void @test3(i32 %k) {
260 ; CHECK-LABEL: @test3(
261 ; CHECK-NEXT: for.body.lr.ph:
262 ; CHECK-NEXT: br label [[FOR_BODY_PEEL_BEGIN:%.*]]
263 ; CHECK: for.body.peel.begin:
264 ; CHECK-NEXT: br label [[FOR_BODY_PEEL:%.*]]
265 ; CHECK: for.body.peel:
266 ; CHECK-NEXT: [[CMP1_PEEL:%.*]] = icmp ugt i32 0, 2
267 ; CHECK-NEXT: br i1 [[CMP1_PEEL]], label [[IF_THEN_PEEL:%.*]], label [[IF_ELSE_PEEL:%.*]]
268 ; CHECK: if.else.peel:
269 ; CHECK-NEXT: call void @f2()
270 ; CHECK-NEXT: br label [[FOR_INC_PEEL:%.*]]
271 ; CHECK: if.then.peel:
272 ; CHECK-NEXT: call void @f1()
273 ; CHECK-NEXT: br label [[FOR_INC_PEEL]]
274 ; CHECK: for.inc.peel:
275 ; CHECK-NEXT: [[INC_PEEL:%.*]] = add nsw i32 0, 1
276 ; CHECK-NEXT: [[CMP_PEEL:%.*]] = icmp slt i32 [[INC_PEEL]], [[K:%.*]]
277 ; CHECK-NEXT: br i1 [[CMP_PEEL]], label [[FOR_BODY_PEEL_NEXT:%.*]], label [[FOR_END:%[^,]*]]
278 ; Verify that MD_loop metadata is dropped.
279 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
280 ; CHECK: for.body.peel.next:
281 ; CHECK-NEXT: br label [[FOR_BODY_PEEL2:%.*]]
282 ; CHECK: for.body.peel2:
283 ; CHECK-NEXT: [[CMP1_PEEL3:%.*]] = icmp ugt i32 [[INC_PEEL]], 2
284 ; CHECK-NEXT: br i1 [[CMP1_PEEL3]], label [[IF_THEN_PEEL5:%.*]], label [[IF_ELSE_PEEL4:%.*]]
285 ; CHECK: if.else.peel4:
286 ; CHECK-NEXT: call void @f2()
287 ; CHECK-NEXT: br label [[FOR_INC_PEEL6:%.*]]
288 ; CHECK: if.then.peel5:
289 ; CHECK-NEXT: call void @f1()
290 ; CHECK-NEXT: br label [[FOR_INC_PEEL6]]
291 ; CHECK: for.inc.peel6:
292 ; CHECK-NEXT: [[INC_PEEL7:%.*]] = add nsw i32 [[INC_PEEL]], 1
293 ; CHECK-NEXT: [[CMP_PEEL8:%.*]] = icmp slt i32 [[INC_PEEL7]], [[K]]
294 ; CHECK-NEXT: br i1 [[CMP_PEEL8]], label [[FOR_BODY_PEEL_NEXT1:%.*]], label [[FOR_END]]
295 ; Verify that MD_loop metadata is dropped.
296 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
297 ; CHECK: for.body.peel.next1:
298 ; CHECK-NEXT: br label [[FOR_BODY_PEEL10:%.*]]
299 ; CHECK: for.body.peel10:
300 ; CHECK-NEXT: [[CMP1_PEEL11:%.*]] = icmp ugt i32 [[INC_PEEL7]], 2
301 ; CHECK-NEXT: br i1 [[CMP1_PEEL11]], label [[IF_THEN_PEEL13:%.*]], label [[IF_ELSE_PEEL12:%.*]]
302 ; CHECK: if.else.peel12:
303 ; CHECK-NEXT: call void @f2()
304 ; CHECK-NEXT: br label [[FOR_INC_PEEL14:%.*]]
305 ; CHECK: if.then.peel13:
306 ; CHECK-NEXT: call void @f1()
307 ; CHECK-NEXT: br label [[FOR_INC_PEEL14]]
308 ; CHECK: for.inc.peel14:
309 ; CHECK-NEXT: [[INC_PEEL15:%.*]] = add nsw i32 [[INC_PEEL7]], 1
310 ; CHECK-NEXT: [[CMP_PEEL16:%.*]] = icmp slt i32 [[INC_PEEL15]], [[K]]
311 ; CHECK-NEXT: br i1 [[CMP_PEEL16]], label [[FOR_BODY_PEEL_NEXT9:%.*]], label [[FOR_END]]
312 ; Verify that MD_loop metadata is dropped.
313 ; CHECK-NOT: , !llvm.loop !{{[0-9]*}}
314 ; CHECK: for.body.peel.next9:
315 ; CHECK-NEXT: br label [[FOR_BODY_PEEL_NEXT17:%.*]]
316 ; CHECK: for.body.peel.next17:
317 ; CHECK-NEXT: br label [[FOR_BODY_LR_PH_PEEL_NEWPH:%.*]]
318 ; CHECK: for.body.lr.ph.peel.newph:
319 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
321 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ [[INC_PEEL15]], [[FOR_BODY_LR_PH_PEEL_NEWPH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
322 ; CHECK-NEXT: br i1 true, label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
324 ; CHECK-NEXT: call void @f1()
325 ; CHECK-NEXT: br label [[FOR_INC]]
327 ; CHECK-NEXT: call void @f2()
328 ; CHECK-NEXT: br label [[FOR_INC]]
330 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_05]], 1
331 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K]]
332 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]], !llvm.loop !{{.*}}
333 ; CHECK: for.end.loopexit:
334 ; CHECK-NEXT: br label [[FOR_END]]
336 ; CHECK-NEXT: ret void
342 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
343 %cmp1 = icmp ugt i32 %i.05, 2
344 br i1 %cmp1, label %if.then, label %if.else
355 %inc = add nsw i32 %i.05, 1
356 %cmp = icmp slt i32 %inc, %k
357 br i1 %cmp, label %for.body, label %for.end, !llvm.loop !3
365 ; Test that we only peel off iterations if it simplifies a condition in the
366 ; loop body after peeling at most MaxPeelCount iterations.
367 define void @test4(i32 %k) {
368 ; CHECK-LABEL: @test4(
369 ; CHECK-NEXT: for.body.lr.ph:
370 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
372 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
373 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[I_05]], 9999
374 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]]
376 ; CHECK-NEXT: call void @f1()
377 ; CHECK-NEXT: br label [[FOR_INC]]
379 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
380 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
381 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
383 ; CHECK-NEXT: ret void
389 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
390 %cmp1 = icmp ugt i32 %i.05, 9999
391 br i1 %cmp1, label %if.then, label %for.inc
398 %inc = add nsw i32 %i.05, 1
399 %cmp = icmp slt i32 %inc, %k
400 br i1 %cmp, label %for.body, label %for.end
406 ; In this case we cannot peel the inner loop, because the condition involves
407 ; the outer induction variable.
408 define void @test5(i32 %k) {
409 ; CHECK-LABEL: @test5(
410 ; CHECK-NEXT: for.body.lr.ph:
411 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
412 ; CHECK: outer.header:
413 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[J_INC:%.*]], [[OUTER_INC:%.*]] ]
414 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
416 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
417 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[J]], 2
418 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
420 ; CHECK-NEXT: call void @f1()
421 ; CHECK-NEXT: br label [[FOR_INC]]
423 ; CHECK-NEXT: call void @f2()
424 ; CHECK-NEXT: br label [[FOR_INC]]
426 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
427 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
428 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[OUTER_INC]]
430 ; CHECK-NEXT: [[J_INC]] = add nsw i32 [[J]], 1
431 ; CHECK-NEXT: [[OUTER_CMP:%.*]] = icmp slt i32 [[J_INC]], [[K]]
432 ; CHECK-NEXT: br i1 [[OUTER_CMP]], label [[OUTER_HEADER]], label [[FOR_END:%.*]]
434 ; CHECK-NEXT: ret void
437 br label %outer.header
440 %j = phi i32 [ 0, %for.body.lr.ph ], [ %j.inc, %outer.inc ]
444 %i.05 = phi i32 [ 0, %outer.header ], [ %inc, %for.inc ]
445 %cmp1 = icmp ult i32 %j, 2
446 br i1 %cmp1, label %if.then, label %if.else
457 %inc = add nsw i32 %i.05, 1
458 %cmp = icmp slt i32 %inc, %k
459 br i1 %cmp, label %for.body, label %outer.inc
462 %j.inc = add nsw i32 %j, 1
463 %outer.cmp = icmp slt i32 %j.inc, %k
464 br i1 %outer.cmp, label %outer.header, label %for.end
471 ; In this test, the condition involves 2 AddRecs. Without evaluating both
472 ; AddRecs, we cannot prove that the condition becomes known in the loop body
474 define void @test6(i32 %k) {
475 ; CHECK-LABEL: @test6(
477 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
479 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
480 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ 4, [[ENTRY]] ], [ [[J_INC:%.*]], [[FOR_INC]] ]
481 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[I_05]], [[J]]
482 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
484 ; CHECK-NEXT: call void @f1()
485 ; CHECK-NEXT: br label [[FOR_INC]]
487 ; CHECK-NEXT: call void @f2()
488 ; CHECK-NEXT: br label [[FOR_INC]]
490 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 2
491 ; CHECK-NEXT: [[J_INC]] = add nsw i32 [[J]], 1
492 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
493 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
495 ; CHECK-NEXT: ret void
501 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
502 %j = phi i32 [ 4, %entry ], [ %j.inc, %for.inc ]
503 %cmp1 = icmp ult i32 %i.05, %j
504 br i1 %cmp1, label %if.then, label %if.else
515 %inc = add nsw i32 %i.05, 2
516 %j.inc = add nsw i32 %j, 1
517 %cmp = icmp slt i32 %inc, %k
518 br i1 %cmp, label %for.body, label %for.end
524 define void @test7(i32 %k) {
525 ; FIXME: Could simplify loop body by peeling one additional iteration after
526 ; i != 3 becomes false
527 ; CHECK-LABEL: @test7(
528 ; CHECK-NEXT: for.body.lr.ph:
529 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
531 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
532 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[I_05]], 3
533 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]]
535 ; CHECK-NEXT: call void @f1()
536 ; CHECK-NEXT: br label [[FOR_INC]]
538 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
539 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
540 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
542 ; CHECK-NEXT: ret void
548 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
549 %cmp1 = icmp ne i32 %i.05, 3
550 br i1 %cmp1, label %if.then, label %for.inc
557 %inc = add nsw i32 %i.05, 1
558 %cmp = icmp slt i32 %inc, %k
559 br i1 %cmp, label %for.body, label %for.end
565 define void @test8(i32 %k) {
566 ; FIXME: Could simplify loop body by peeling one additional iteration after
567 ; i == 3 becomes true.
568 ; CHECK-LABEL: @test8(
569 ; CHECK-NEXT: for.body.lr.ph:
570 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
572 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
573 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[I_05]], 3
574 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]]
576 ; CHECK-NEXT: call void @f1()
577 ; CHECK-NEXT: br label [[FOR_INC]]
579 ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_05]], 1
580 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
581 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
583 ; CHECK-NEXT: ret void
589 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
590 %cmp1 = icmp eq i32 %i.05, 3
591 br i1 %cmp1, label %if.then, label %for.inc
598 %inc = add nsw i32 %i.05, 1
599 %cmp = icmp slt i32 %inc, %k
600 br i1 %cmp, label %for.body, label %for.end
606 ; Comparison with non-monotonic predicate due to possible wrapping, loop
607 ; body cannot be simplified.
608 define void @test9(i32 %k) {
609 ; CHECK-LABEL: @test9(
610 ; CHECK-NEXT: for.body.lr.ph:
611 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
613 ; CHECK-NEXT: [[I_05:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
614 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[I_05]], 3
615 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[FOR_INC]]
617 ; CHECK-NEXT: call void @f1()
618 ; CHECK-NEXT: br label [[FOR_INC]]
620 ; CHECK-NEXT: [[INC]] = add i32 [[I_05]], 1
621 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[K:%.*]]
622 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
624 ; CHECK-NEXT: ret void
630 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
631 %cmp1 = icmp slt i32 %i.05, 3
632 br i1 %cmp1, label %if.then, label %for.inc
639 %inc = add i32 %i.05, 1
640 %cmp = icmp slt i32 %inc, %k
641 br i1 %cmp, label %for.body, label %for.end
646 ; CHECK-NOT: llvm.loop.unroll.disable