1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -loop-deletion -S | FileCheck %s
3 ; RUN: opt < %s -passes='loop(loop-deletion)' -S | FileCheck %s
5 ; The idea is that we know that %is.positive is true on the 1st iteration,
6 ; it means that we can evaluate %merge.phi = %sub on the 1st iteration,
7 ; and therefore prove that %sum.next = %sum + %sub = %sum + %limit - %sum = %limit,
8 ; and predicate is false.
10 ; TODO: We can break the backedge here.
11 define i32 @test_ne(i32 %limit) {
12 ; CHECK-LABEL: @test_ne(
14 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
15 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
16 ; CHECK: loop.preheader:
17 ; CHECK-NEXT: br label [[LOOP:%.*]]
19 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
20 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
21 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
22 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
24 ; CHECK-NEXT: br label [[BACKEDGE]]
26 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
27 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
28 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], [[LIMIT]]
29 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
31 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
32 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
34 ; CHECK-NEXT: unreachable
37 %loop_guard = icmp sgt i32 %limit, 0
38 br i1 %loop_guard, label %loop, label %failure
40 loop: ; preds = %backedge, %entry
41 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
42 %sub = sub i32 %limit, %sum
43 %is.positive = icmp sgt i32 %sub, 0
44 br i1 %is.positive, label %backedge, label %if.false
46 if.false: ; preds = %loop
49 backedge: ; preds = %if.false, %loop
50 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
51 %sum.next = add i32 %sum, %merge.phi
52 %loop.cond = icmp ne i32 %sum.next, %limit
53 br i1 %loop.cond, label %loop, label %done
55 done: ; preds = %backedge
56 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
57 ret i32 %sum.next.lcssa
63 ; TODO: We can break the backedge here.
64 define i32 @test_slt(i32 %limit) {
65 ; CHECK-LABEL: @test_slt(
67 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
68 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
69 ; CHECK: loop.preheader:
70 ; CHECK-NEXT: br label [[LOOP:%.*]]
72 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
73 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
74 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
75 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
77 ; CHECK-NEXT: br label [[BACKEDGE]]
79 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
80 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
81 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp slt i32 [[SUM_NEXT]], [[LIMIT]]
82 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
84 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
85 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
87 ; CHECK-NEXT: unreachable
90 %loop_guard = icmp sgt i32 %limit, 0
91 br i1 %loop_guard, label %loop, label %failure
93 loop: ; preds = %backedge, %entry
94 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
95 %sub = sub i32 %limit, %sum
96 %is.positive = icmp sgt i32 %sub, 0
97 br i1 %is.positive, label %backedge, label %if.false
99 if.false: ; preds = %loop
102 backedge: ; preds = %if.false, %loop
103 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
104 %sum.next = add i32 %sum, %merge.phi
105 %loop.cond = icmp slt i32 %sum.next, %limit
106 br i1 %loop.cond, label %loop, label %done
108 done: ; preds = %backedge
109 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
110 ret i32 %sum.next.lcssa
116 ; TODO: We can break the backedge here.
117 define i32 @test_ult(i32 %limit) {
118 ; CHECK-LABEL: @test_ult(
120 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
121 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
122 ; CHECK: loop.preheader:
123 ; CHECK-NEXT: br label [[LOOP:%.*]]
125 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
126 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
127 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
128 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
130 ; CHECK-NEXT: br label [[BACKEDGE]]
132 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
133 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
134 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ult i32 [[SUM_NEXT]], [[LIMIT]]
135 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
137 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
138 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
140 ; CHECK-NEXT: unreachable
143 %loop_guard = icmp sgt i32 %limit, 0
144 br i1 %loop_guard, label %loop, label %failure
146 loop: ; preds = %backedge, %entry
147 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
148 %sub = sub i32 %limit, %sum
149 %is.positive = icmp sgt i32 %sub, 0
150 br i1 %is.positive, label %backedge, label %if.false
152 if.false: ; preds = %loop
155 backedge: ; preds = %if.false, %loop
156 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
157 %sum.next = add i32 %sum, %merge.phi
158 %loop.cond = icmp ult i32 %sum.next, %limit
159 br i1 %loop.cond, label %loop, label %done
161 done: ; preds = %backedge
162 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
163 ret i32 %sum.next.lcssa
169 ; TODO: We can break the backedge here.
170 define i32 @test_sgt(i32 %limit) {
171 ; CHECK-LABEL: @test_sgt(
173 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
174 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
175 ; CHECK: loop.preheader:
176 ; CHECK-NEXT: br label [[LOOP:%.*]]
178 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
179 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
180 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
181 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
183 ; CHECK-NEXT: br label [[BACKEDGE]]
185 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
186 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
187 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp sgt i32 [[SUM_NEXT]], [[LIMIT]]
188 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
190 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
191 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
193 ; CHECK-NEXT: unreachable
196 %loop_guard = icmp sgt i32 %limit, 0
197 br i1 %loop_guard, label %loop, label %failure
199 loop: ; preds = %backedge, %entry
200 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
201 %sub = sub i32 %limit, %sum
202 %is.positive = icmp sgt i32 %sub, 0
203 br i1 %is.positive, label %backedge, label %if.false
205 if.false: ; preds = %loop
208 backedge: ; preds = %if.false, %loop
209 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
210 %sum.next = add i32 %sum, %merge.phi
211 %loop.cond = icmp sgt i32 %sum.next, %limit
212 br i1 %loop.cond, label %loop, label %done
214 done: ; preds = %backedge
215 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
216 ret i32 %sum.next.lcssa
222 ; TODO: We can break the backedge here.
223 define i32 @test_ugt(i32 %limit) {
224 ; CHECK-LABEL: @test_ugt(
226 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
227 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
228 ; CHECK: loop.preheader:
229 ; CHECK-NEXT: br label [[LOOP:%.*]]
231 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
232 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
233 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
234 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
236 ; CHECK-NEXT: br label [[BACKEDGE]]
238 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
239 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
240 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ugt i32 [[SUM_NEXT]], [[LIMIT]]
241 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
243 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
244 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
246 ; CHECK-NEXT: unreachable
249 %loop_guard = icmp sgt i32 %limit, 0
250 br i1 %loop_guard, label %loop, label %failure
252 loop: ; preds = %backedge, %entry
253 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
254 %sub = sub i32 %limit, %sum
255 %is.positive = icmp sgt i32 %sub, 0
256 br i1 %is.positive, label %backedge, label %if.false
258 if.false: ; preds = %loop
261 backedge: ; preds = %if.false, %loop
262 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
263 %sum.next = add i32 %sum, %merge.phi
264 %loop.cond = icmp ugt i32 %sum.next, %limit
265 br i1 %loop.cond, label %loop, label %done
267 done: ; preds = %backedge
268 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
269 ret i32 %sum.next.lcssa
275 ; TODO: We can break the backedge here.
276 define i32 @test_multiple_pred(i32 %limit) {
277 ; CHECK-LABEL: @test_multiple_pred(
279 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
280 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
281 ; CHECK: loop.preheader:
282 ; CHECK-NEXT: br label [[LOOP:%.*]]
284 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
285 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
286 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
287 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
289 ; CHECK-NEXT: switch i32 [[LIMIT]], label [[FAILURE_LOOPEXIT:%.*]] [
290 ; CHECK-NEXT: i32 100, label [[BACKEDGE]]
291 ; CHECK-NEXT: i32 200, label [[BACKEDGE]]
294 ; CHECK-NEXT: br label [[BACKEDGE]]
296 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[IF_TRUE]] ], [ [[SUB]], [[IF_TRUE]] ]
297 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
298 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], [[LIMIT]]
299 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
301 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
302 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
303 ; CHECK: failure.loopexit:
304 ; CHECK-NEXT: br label [[FAILURE]]
306 ; CHECK-NEXT: unreachable
309 %loop_guard = icmp sgt i32 %limit, 0
310 br i1 %loop_guard, label %loop, label %failure
312 loop: ; preds = %backedge, %entry
313 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
314 %sub = sub i32 %limit, %sum
315 %is.positive = icmp sgt i32 %sub, 0
316 br i1 %is.positive, label %if.true, label %if.false
319 switch i32 %limit, label %failure [
320 i32 100, label %backedge
321 i32 200, label %backedge
324 if.false: ; preds = %loop
328 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %if.true ], [ %sub, %if.true ]
329 %sum.next = add i32 %sum, %merge.phi
330 %loop.cond = icmp ne i32 %sum.next, %limit
331 br i1 %loop.cond, label %loop, label %done
333 done: ; preds = %backedge
334 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
335 ret i32 %sum.next.lcssa
341 define i32 @test_ne_const() {
342 ; CHECK-LABEL: @test_ne_const(
344 ; CHECK-NEXT: br label [[LOOP:%.*]]
346 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
347 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
348 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
349 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
351 ; CHECK-NEXT: br label [[BACKEDGE]]
353 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
354 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
355 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
356 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
357 ; CHECK: backedge.loop_crit_edge:
358 ; CHECK-NEXT: unreachable
360 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
361 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
363 ; CHECK-NEXT: unreachable
369 loop: ; preds = %backedge, %entry
370 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
371 %sub = sub i32 4, %sum
372 %is.positive = icmp sgt i32 %sub, 0
373 br i1 %is.positive, label %backedge, label %if.false
375 if.false: ; preds = %loop
378 backedge: ; preds = %if.false, %loop
379 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
380 %sum.next = add i32 %sum, %merge.phi
381 %loop.cond = icmp ne i32 %sum.next, 4
382 br i1 %loop.cond, label %loop, label %done
384 done: ; preds = %backedge
385 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
386 ret i32 %sum.next.lcssa
392 define i32 @test_slt_const() {
393 ; CHECK-LABEL: @test_slt_const(
395 ; CHECK-NEXT: br label [[LOOP:%.*]]
397 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
398 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
399 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
400 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
402 ; CHECK-NEXT: br label [[BACKEDGE]]
404 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
405 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
406 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp slt i32 [[SUM_NEXT]], 4
407 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
408 ; CHECK: backedge.loop_crit_edge:
409 ; CHECK-NEXT: unreachable
411 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
412 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
414 ; CHECK-NEXT: unreachable
420 loop: ; preds = %backedge, %entry
421 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
422 %sub = sub i32 4, %sum
423 %is.positive = icmp sgt i32 %sub, 0
424 br i1 %is.positive, label %backedge, label %if.false
426 if.false: ; preds = %loop
429 backedge: ; preds = %if.false, %loop
430 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
431 %sum.next = add i32 %sum, %merge.phi
432 %loop.cond = icmp slt i32 %sum.next, 4
433 br i1 %loop.cond, label %loop, label %done
435 done: ; preds = %backedge
436 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
437 ret i32 %sum.next.lcssa
443 define i32 @test_ult_const() {
444 ; CHECK-LABEL: @test_ult_const(
446 ; CHECK-NEXT: br label [[LOOP:%.*]]
448 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
449 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
450 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
451 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
453 ; CHECK-NEXT: br label [[BACKEDGE]]
455 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
456 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
457 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ult i32 [[SUM_NEXT]], 4
458 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
459 ; CHECK: backedge.loop_crit_edge:
460 ; CHECK-NEXT: unreachable
462 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
463 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
465 ; CHECK-NEXT: unreachable
471 loop: ; preds = %backedge, %entry
472 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
473 %sub = sub i32 4, %sum
474 %is.positive = icmp sgt i32 %sub, 0
475 br i1 %is.positive, label %backedge, label %if.false
477 if.false: ; preds = %loop
480 backedge: ; preds = %if.false, %loop
481 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
482 %sum.next = add i32 %sum, %merge.phi
483 %loop.cond = icmp ult i32 %sum.next, 4
484 br i1 %loop.cond, label %loop, label %done
486 done: ; preds = %backedge
487 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
488 ret i32 %sum.next.lcssa
494 define i32 @test_sgt_const() {
495 ; CHECK-LABEL: @test_sgt_const(
497 ; CHECK-NEXT: br label [[LOOP:%.*]]
499 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
500 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
501 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
502 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
504 ; CHECK-NEXT: br label [[BACKEDGE]]
506 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
507 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
508 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp sgt i32 [[SUM_NEXT]], 4
509 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
510 ; CHECK: backedge.loop_crit_edge:
511 ; CHECK-NEXT: unreachable
513 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
514 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
516 ; CHECK-NEXT: unreachable
522 loop: ; preds = %backedge, %entry
523 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
524 %sub = sub i32 4, %sum
525 %is.positive = icmp sgt i32 %sub, 0
526 br i1 %is.positive, label %backedge, label %if.false
528 if.false: ; preds = %loop
531 backedge: ; preds = %if.false, %loop
532 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
533 %sum.next = add i32 %sum, %merge.phi
534 %loop.cond = icmp sgt i32 %sum.next, 4
535 br i1 %loop.cond, label %loop, label %done
537 done: ; preds = %backedge
538 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
539 ret i32 %sum.next.lcssa
545 define i32 @test_ugt_const() {
546 ; CHECK-LABEL: @test_ugt_const(
548 ; CHECK-NEXT: br label [[LOOP:%.*]]
550 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
551 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
552 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
553 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
555 ; CHECK-NEXT: br label [[BACKEDGE]]
557 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
558 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
559 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ugt i32 [[SUM_NEXT]], 4
560 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
561 ; CHECK: backedge.loop_crit_edge:
562 ; CHECK-NEXT: unreachable
564 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
565 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
567 ; CHECK-NEXT: unreachable
573 loop: ; preds = %backedge, %entry
574 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
575 %sub = sub i32 4, %sum
576 %is.positive = icmp sgt i32 %sub, 0
577 br i1 %is.positive, label %backedge, label %if.false
579 if.false: ; preds = %loop
582 backedge: ; preds = %if.false, %loop
583 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
584 %sum.next = add i32 %sum, %merge.phi
585 %loop.cond = icmp ugt i32 %sum.next, 4
586 br i1 %loop.cond, label %loop, label %done
588 done: ; preds = %backedge
589 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
590 ret i32 %sum.next.lcssa
596 define i32 @test_multiple_pred_const() {
597 ; CHECK-LABEL: @test_multiple_pred_const(
599 ; CHECK-NEXT: br label [[LOOP:%.*]]
601 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
602 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
603 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
604 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
606 ; CHECK-NEXT: switch i32 4, label [[FAILURE:%.*]] [
607 ; CHECK-NEXT: i32 100, label [[BACKEDGE:%.*]]
608 ; CHECK-NEXT: i32 200, label [[BACKEDGE]]
611 ; CHECK-NEXT: br label [[BACKEDGE]]
613 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[IF_TRUE]] ], [ [[SUB]], [[IF_TRUE]] ]
614 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
615 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
616 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
617 ; CHECK: backedge.loop_crit_edge:
618 ; CHECK-NEXT: unreachable
620 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
621 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
623 ; CHECK-NEXT: unreachable
629 loop: ; preds = %backedge, %entry
630 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
631 %sub = sub i32 4, %sum
632 %is.positive = icmp sgt i32 %sub, 0
633 br i1 %is.positive, label %if.true, label %if.false
636 switch i32 4, label %failure [
637 i32 100, label %backedge
638 i32 200, label %backedge
641 if.false: ; preds = %loop
645 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %if.true ], [ %sub, %if.true ]
646 %sum.next = add i32 %sum, %merge.phi
647 %loop.cond = icmp ne i32 %sum.next, 4
648 br i1 %loop.cond, label %loop, label %done
650 done: ; preds = %backedge
651 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
652 ret i32 %sum.next.lcssa
658 define i32 @test_multiple_pred_2(i1 %cond, i1 %cond2) {
659 ; CHECK-LABEL: @test_multiple_pred_2(
661 ; CHECK-NEXT: br label [[LOOP:%.*]]
663 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
664 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
665 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
666 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
668 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
670 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
672 ; CHECK-NEXT: br label [[BACKEDGE]]
674 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
676 ; CHECK-NEXT: br label [[BACKEDGE]]
678 ; CHECK-NEXT: br label [[BACKEDGE]]
680 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ [[SUB]], [[IF_TRUE_1]] ], [ [[SUB]], [[IF_TRUE_2]] ]
681 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
682 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
683 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
684 ; CHECK: backedge.loop_crit_edge:
685 ; CHECK-NEXT: unreachable
687 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
688 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
690 ; CHECK-NEXT: unreachable
696 loop: ; preds = %backedge, %entry
697 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
698 %sub = sub i32 4, %sum
699 %is.positive = icmp sgt i32 %sub, 0
700 br i1 %is.positive, label %if.true, label %if.false
703 br i1 %cond, label %if.true.1, label %if.true.2
711 if.false: ; preds = %loop
712 br i1 %cond2, label %if.false.1, label %if.false.2
721 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ %sub, %if.true.1 ], [ %sub, %if.true.2 ]
722 %sum.next = add i32 %sum, %merge.phi
723 %loop.cond = icmp ne i32 %sum.next, 4
724 br i1 %loop.cond, label %loop, label %done
726 done: ; preds = %backedge
727 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
728 ret i32 %sum.next.lcssa
734 define i32 @test_multiple_pred_undef_1(i1 %cond, i1 %cond2) {
735 ; CHECK-LABEL: @test_multiple_pred_undef_1(
737 ; CHECK-NEXT: br label [[LOOP:%.*]]
739 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
740 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
741 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
742 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
744 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
746 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
748 ; CHECK-NEXT: br label [[BACKEDGE]]
750 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
752 ; CHECK-NEXT: br label [[BACKEDGE]]
754 ; CHECK-NEXT: br label [[BACKEDGE]]
756 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ [[SUB]], [[IF_TRUE_1]] ], [ undef, [[IF_TRUE_2]] ]
757 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
758 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
759 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
760 ; CHECK: backedge.loop_crit_edge:
761 ; CHECK-NEXT: unreachable
763 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
764 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
766 ; CHECK-NEXT: unreachable
771 loop: ; preds = %backedge, %entry
772 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
773 %sub = sub i32 4, %sum
774 %is.positive = icmp sgt i32 %sub, 0
775 br i1 %is.positive, label %if.true, label %if.false
778 br i1 %cond, label %if.true.1, label %if.true.2
786 if.false: ; preds = %loop
787 br i1 %cond2, label %if.false.1, label %if.false.2
796 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ %sub, %if.true.1 ], [ undef, %if.true.2 ]
797 %sum.next = add i32 %sum, %merge.phi
798 %loop.cond = icmp ne i32 %sum.next, 4
799 br i1 %loop.cond, label %loop, label %done
801 done: ; preds = %backedge
802 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
803 ret i32 %sum.next.lcssa
809 define i32 @test_multiple_pred_undef_2(i1 %cond, i1 %cond2) {
810 ; CHECK-LABEL: @test_multiple_pred_undef_2(
812 ; CHECK-NEXT: br label [[LOOP:%.*]]
814 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
815 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
816 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
817 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
819 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
821 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
823 ; CHECK-NEXT: br label [[BACKEDGE]]
825 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
827 ; CHECK-NEXT: br label [[BACKEDGE]]
829 ; CHECK-NEXT: br label [[BACKEDGE]]
831 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ undef, [[IF_TRUE_1]] ], [ [[SUB]], [[IF_TRUE_2]] ]
832 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
833 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
834 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
835 ; CHECK: backedge.loop_crit_edge:
836 ; CHECK-NEXT: unreachable
838 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
839 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
841 ; CHECK-NEXT: unreachable
846 loop: ; preds = %backedge, %entry
847 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
848 %sub = sub i32 4, %sum
849 %is.positive = icmp sgt i32 %sub, 0
850 br i1 %is.positive, label %if.true, label %if.false
853 br i1 %cond, label %if.true.1, label %if.true.2
861 if.false: ; preds = %loop
862 br i1 %cond2, label %if.false.1, label %if.false.2
871 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ undef, %if.true.1 ], [ %sub, %if.true.2 ]
872 %sum.next = add i32 %sum, %merge.phi
873 %loop.cond = icmp ne i32 %sum.next, 4
874 br i1 %loop.cond, label %loop, label %done
876 done: ; preds = %backedge
877 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
878 ret i32 %sum.next.lcssa
884 define i32 @test_multiple_pred_undef_3(i1 %cond, i1 %cond2) {
885 ; CHECK-LABEL: @test_multiple_pred_undef_3(
887 ; CHECK-NEXT: br label [[LOOP:%.*]]
889 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
890 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
891 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
892 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
894 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
896 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
898 ; CHECK-NEXT: br label [[BACKEDGE]]
900 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
902 ; CHECK-NEXT: br label [[BACKEDGE]]
904 ; CHECK-NEXT: br label [[BACKEDGE]]
906 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ undef, [[IF_TRUE_1]] ], [ undef, [[IF_TRUE_2]] ]
907 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
908 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
909 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
910 ; CHECK: backedge.loop_crit_edge:
911 ; CHECK-NEXT: unreachable
913 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
914 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
916 ; CHECK-NEXT: unreachable
921 loop: ; preds = %backedge, %entry
922 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
923 %sub = sub i32 4, %sum
924 %is.positive = icmp sgt i32 %sub, 0
925 br i1 %is.positive, label %if.true, label %if.false
928 br i1 %cond, label %if.true.1, label %if.true.2
936 if.false: ; preds = %loop
937 br i1 %cond2, label %if.false.1, label %if.false.2
946 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ undef, %if.true.1 ], [ undef, %if.true.2 ]
947 %sum.next = add i32 %sum, %merge.phi
948 %loop.cond = icmp ne i32 %sum.next, 4
949 br i1 %loop.cond, label %loop, label %done
951 done: ; preds = %backedge
952 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
953 ret i32 %sum.next.lcssa
959 ; TODO: We can break the backedge here.
960 define i32 @test_select(i32 %limit) {
961 ; CHECK-LABEL: @test_select(
963 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
964 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
965 ; CHECK: loop.preheader:
966 ; CHECK-NEXT: br label [[LOOP:%.*]]
968 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
969 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
970 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
971 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 0
972 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[SEL]]
973 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], [[LIMIT]]
974 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
976 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP]] ]
977 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
979 ; CHECK-NEXT: unreachable
982 %loop_guard = icmp sgt i32 %limit, 0
983 br i1 %loop_guard, label %loop, label %failure
985 loop: ; preds = %backedge, %entry
986 %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop ]
987 %sub = sub i32 %limit, %sum
988 %is.positive = icmp sgt i32 %sub, 0
989 %sel = select i1 %is.positive, i32 %sub, i32 0
990 %sum.next = add i32 %sum, %sel
991 %loop.cond = icmp ne i32 %sum.next, %limit
992 br i1 %loop.cond, label %loop, label %done
994 done: ; preds = %backedge
995 %sum.next.lcssa = phi i32 [ %sum.next, %loop ]
996 ret i32 %sum.next.lcssa
1002 ; TODO: We can break the backedge here.
1003 define i32 @test_select_const(i32 %x) {
1004 ; CHECK-LABEL: @test_select_const(
1005 ; CHECK-NEXT: entry:
1006 ; CHECK-NEXT: br label [[LOOP:%.*]]
1008 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[SUM_NEXT:%.*]], [[BACKEDGE:%.*]] ]
1009 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
1010 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
1011 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 [[X:%.*]]
1012 ; CHECK-NEXT: [[SEL_COND:%.*]] = icmp sgt i32 [[SEL]], 0
1013 ; CHECK-NEXT: br i1 [[SEL_COND]], label [[BACKEDGE]], label [[IF_FALSE:%.*]]
1015 ; CHECK-NEXT: br label [[BACKEDGE]]
1017 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
1018 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[MERGE_PHI]]
1019 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
1020 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
1022 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1023 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1028 loop: ; preds = %backedge, %entry
1029 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1030 %sub = sub i32 4, %sum
1031 %is.positive = icmp sgt i32 %sub, 0
1032 %sel = select i1 %is.positive, i32 %sub, i32 %x
1033 %sel.cond = icmp sgt i32 %sel, 0
1034 br i1 %sel.cond, label %backedge, label %if.false
1036 if.false: ; preds = %loop
1039 backedge: ; preds = %if.false, %loop
1040 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
1041 %sum.next = add i32 %sum, %merge.phi
1042 %loop.cond = icmp ne i32 %sum.next, 4
1043 br i1 %loop.cond, label %loop, label %done
1045 done: ; preds = %backedge
1046 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1047 ret i32 %sum.next.lcssa
1054 ; Here switch will always jump to the default label
1055 define i32 @test_switch_ne_default() {
1056 ; CHECK-LABEL: @test_switch_ne_default(
1057 ; CHECK-NEXT: entry:
1058 ; CHECK-NEXT: br label [[LOOP:%.*]]
1060 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
1061 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
1062 ; CHECK-NEXT: switch i32 [[SUB]], label [[DEFAULT:%.*]] [
1063 ; CHECK-NEXT: i32 0, label [[ONZERO:%.*]]
1064 ; CHECK-NEXT: i32 1, label [[ONONE:%.*]]
1065 ; CHECK-NEXT: i32 2, label [[ONTWO:%.*]]
1068 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
1070 ; CHECK-NEXT: br label [[BACKEDGE]]
1072 ; CHECK-NEXT: br label [[BACKEDGE]]
1074 ; CHECK-NEXT: br label [[BACKEDGE]]
1076 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ [[SUB]], [[DEFAULT]] ], [ 0, [[ONZERO]] ], [ 1, [[ONONE]] ], [ 2, [[ONTWO]] ]
1077 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
1078 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
1079 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
1080 ; CHECK: backedge.loop_crit_edge:
1081 ; CHECK-NEXT: unreachable
1083 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1084 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1089 loop: ; preds = %backedge, %entry
1090 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1091 %sub = sub i32 4, %sum
1092 switch i32 %sub, label %default [
1093 i32 0, label %onzero
1098 default: ; preds = %loop
1101 onzero: ; preds = %loop
1104 onone: ; preds = %loop
1107 ontwo: ; preds = %loop
1110 backedge: ; preds = %ontwo, %onone, %onzero, %default
1111 %merge.phi = phi i32 [ %sub, %default ], [ 0, %onzero ], [ 1, %onone ], [ 2, %ontwo ]
1112 %sum.next = add i32 %sum, %merge.phi
1113 %loop.cond = icmp ne i32 %sum.next, 4
1114 br i1 %loop.cond, label %loop, label %done
1116 done: ; preds = %backedge
1117 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1118 ret i32 %sum.next.lcssa
1121 ; Here switch will always jump to the %ontwo label
1122 define i32 @test_switch_ne_one_case() {
1123 ; CHECK-LABEL: @test_switch_ne_one_case(
1124 ; CHECK-NEXT: entry:
1125 ; CHECK-NEXT: br label [[LOOP:%.*]]
1127 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
1128 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
1129 ; CHECK-NEXT: switch i32 [[SUB]], label [[DEFAULT:%.*]] [
1130 ; CHECK-NEXT: i32 0, label [[ONZERO:%.*]]
1131 ; CHECK-NEXT: i32 1, label [[ONONE:%.*]]
1132 ; CHECK-NEXT: i32 4, label [[ONTWO:%.*]]
1135 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
1137 ; CHECK-NEXT: br label [[BACKEDGE]]
1139 ; CHECK-NEXT: br label [[BACKEDGE]]
1141 ; CHECK-NEXT: br label [[BACKEDGE]]
1143 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 2, [[DEFAULT]] ], [ 0, [[ONZERO]] ], [ 1, [[ONONE]] ], [ [[SUB]], [[ONTWO]] ]
1144 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
1145 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
1146 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
1147 ; CHECK: backedge.loop_crit_edge:
1148 ; CHECK-NEXT: unreachable
1150 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1151 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1156 loop: ; preds = %backedge, %entry
1157 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1158 %sub = sub i32 4, %sum
1159 switch i32 %sub, label %default [
1160 i32 0, label %onzero
1165 default: ; preds = %loop
1168 onzero: ; preds = %loop
1171 onone: ; preds = %loop
1174 ontwo: ; preds = %loop
1177 backedge: ; preds = %ontwo, %onone, %onzero, %default
1178 %merge.phi = phi i32 [ 2, %default ], [ 0, %onzero ], [ 1, %onone ], [ %sub, %ontwo ]
1179 %sum.next = add i32 %sum, %merge.phi
1180 %loop.cond = icmp ne i32 %sum.next, 4
1181 br i1 %loop.cond, label %loop, label %done
1183 done: ; preds = %backedge
1184 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1185 ret i32 %sum.next.lcssa
1188 ; Here switch will always jump to the %backedge label, but there are two jumps to this label in switch
1189 define i32 @test_switch_ne_one_case_identical_jumps() {
1190 ; CHECK-LABEL: @test_switch_ne_one_case_identical_jumps(
1191 ; CHECK-NEXT: entry:
1192 ; CHECK-NEXT: br label [[LOOP:%.*]]
1194 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
1195 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 2, [[SUM]]
1196 ; CHECK-NEXT: switch i32 [[SUB]], label [[DEFAULT:%.*]] [
1197 ; CHECK-NEXT: i32 0, label [[FIRST_BLOCK:%.*]]
1198 ; CHECK-NEXT: i32 1, label [[BACKEDGE:%.*]]
1199 ; CHECK-NEXT: i32 2, label [[BACKEDGE]]
1202 ; CHECK-NEXT: br label [[BACKEDGE]]
1203 ; CHECK: first_block:
1204 ; CHECK-NEXT: br label [[BACKEDGE]]
1206 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[DEFAULT]] ], [ 1, [[FIRST_BLOCK]] ], [ [[SUB]], [[LOOP]] ], [ [[SUB]], [[LOOP]] ]
1207 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
1208 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 2
1209 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[BACKEDGE_LOOP_CRIT_EDGE:%.*]], label [[DONE:%.*]]
1210 ; CHECK: backedge.loop_crit_edge:
1211 ; CHECK-NEXT: unreachable
1213 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1214 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1219 loop: ; preds = %backedge, %entry
1220 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1221 %sub = sub i32 2, %sum
1222 switch i32 %sub, label %default [
1223 i32 0, label %first_block
1224 i32 1, label %backedge
1225 i32 2, label %backedge
1228 default: ; preds = %loop
1231 first_block: ; preds = %loop
1234 backedge: ; preds = %first_block, %default, %loop, %loop
1235 %merge.phi = phi i32 [ 0, %default ], [ 1, %first_block ], [ %sub, %loop ], [ %sub, %loop ]
1236 %sum.next = add i32 %sum, %merge.phi
1237 %loop.cond = icmp ne i32 %sum.next, 2
1238 br i1 %loop.cond, label %loop, label %done
1240 done: ; preds = %backedge
1241 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1242 ret i32 %sum.next.lcssa