1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=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 label [[DONE:%.*]]
358 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
359 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
361 ; CHECK-NEXT: unreachable
367 loop: ; preds = %backedge, %entry
368 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
369 %sub = sub i32 4, %sum
370 %is.positive = icmp sgt i32 %sub, 0
371 br i1 %is.positive, label %backedge, label %if.false
373 if.false: ; preds = %loop
376 backedge: ; preds = %if.false, %loop
377 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
378 %sum.next = add i32 %sum, %merge.phi
379 %loop.cond = icmp ne i32 %sum.next, 4
380 br i1 %loop.cond, label %loop, label %done
382 done: ; preds = %backedge
383 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
384 ret i32 %sum.next.lcssa
390 define i32 @test_slt_const() {
391 ; CHECK-LABEL: @test_slt_const(
393 ; CHECK-NEXT: br label [[LOOP:%.*]]
395 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
396 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
397 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
398 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
400 ; CHECK-NEXT: br label [[BACKEDGE]]
402 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
403 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
404 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp slt i32 [[SUM_NEXT]], 4
405 ; CHECK-NEXT: br label [[DONE:%.*]]
407 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
408 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
410 ; CHECK-NEXT: unreachable
416 loop: ; preds = %backedge, %entry
417 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
418 %sub = sub i32 4, %sum
419 %is.positive = icmp sgt i32 %sub, 0
420 br i1 %is.positive, label %backedge, label %if.false
422 if.false: ; preds = %loop
425 backedge: ; preds = %if.false, %loop
426 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
427 %sum.next = add i32 %sum, %merge.phi
428 %loop.cond = icmp slt i32 %sum.next, 4
429 br i1 %loop.cond, label %loop, label %done
431 done: ; preds = %backedge
432 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
433 ret i32 %sum.next.lcssa
439 define i32 @test_ult_const() {
440 ; CHECK-LABEL: @test_ult_const(
442 ; CHECK-NEXT: br label [[LOOP:%.*]]
444 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
445 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
446 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
447 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
449 ; CHECK-NEXT: br label [[BACKEDGE]]
451 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
452 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
453 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ult i32 [[SUM_NEXT]], 4
454 ; CHECK-NEXT: br label [[DONE:%.*]]
456 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
457 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
459 ; CHECK-NEXT: unreachable
465 loop: ; preds = %backedge, %entry
466 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
467 %sub = sub i32 4, %sum
468 %is.positive = icmp sgt i32 %sub, 0
469 br i1 %is.positive, label %backedge, label %if.false
471 if.false: ; preds = %loop
474 backedge: ; preds = %if.false, %loop
475 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
476 %sum.next = add i32 %sum, %merge.phi
477 %loop.cond = icmp ult i32 %sum.next, 4
478 br i1 %loop.cond, label %loop, label %done
480 done: ; preds = %backedge
481 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
482 ret i32 %sum.next.lcssa
488 define i32 @test_sgt_const() {
489 ; CHECK-LABEL: @test_sgt_const(
491 ; CHECK-NEXT: br label [[LOOP:%.*]]
493 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
494 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
495 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
496 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
498 ; CHECK-NEXT: br label [[BACKEDGE]]
500 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
501 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
502 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp sgt i32 [[SUM_NEXT]], 4
503 ; CHECK-NEXT: br label [[DONE:%.*]]
505 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
506 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
508 ; CHECK-NEXT: unreachable
514 loop: ; preds = %backedge, %entry
515 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
516 %sub = sub i32 4, %sum
517 %is.positive = icmp sgt i32 %sub, 0
518 br i1 %is.positive, label %backedge, label %if.false
520 if.false: ; preds = %loop
523 backedge: ; preds = %if.false, %loop
524 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
525 %sum.next = add i32 %sum, %merge.phi
526 %loop.cond = icmp sgt i32 %sum.next, 4
527 br i1 %loop.cond, label %loop, label %done
529 done: ; preds = %backedge
530 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
531 ret i32 %sum.next.lcssa
537 define i32 @test_ugt_const() {
538 ; CHECK-LABEL: @test_ugt_const(
540 ; CHECK-NEXT: br label [[LOOP:%.*]]
542 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
543 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
544 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
545 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
547 ; CHECK-NEXT: br label [[BACKEDGE]]
549 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
550 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
551 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ugt i32 [[SUM_NEXT]], 4
552 ; CHECK-NEXT: br label [[DONE:%.*]]
554 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
555 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
557 ; CHECK-NEXT: unreachable
563 loop: ; preds = %backedge, %entry
564 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
565 %sub = sub i32 4, %sum
566 %is.positive = icmp sgt i32 %sub, 0
567 br i1 %is.positive, label %backedge, label %if.false
569 if.false: ; preds = %loop
572 backedge: ; preds = %if.false, %loop
573 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
574 %sum.next = add i32 %sum, %merge.phi
575 %loop.cond = icmp ugt i32 %sum.next, 4
576 br i1 %loop.cond, label %loop, label %done
578 done: ; preds = %backedge
579 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
580 ret i32 %sum.next.lcssa
586 define i32 @test_multiple_pred_const() {
587 ; CHECK-LABEL: @test_multiple_pred_const(
589 ; CHECK-NEXT: br label [[LOOP:%.*]]
591 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
592 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
593 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
594 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
596 ; CHECK-NEXT: switch i32 4, label [[FAILURE:%.*]] [
597 ; CHECK-NEXT: i32 100, label [[BACKEDGE:%.*]]
598 ; CHECK-NEXT: i32 200, label [[BACKEDGE]]
601 ; CHECK-NEXT: br label [[BACKEDGE]]
603 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[IF_TRUE]] ], [ [[SUB]], [[IF_TRUE]] ]
604 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
605 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
606 ; CHECK-NEXT: br label [[DONE:%.*]]
608 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
609 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
611 ; CHECK-NEXT: unreachable
617 loop: ; preds = %backedge, %entry
618 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
619 %sub = sub i32 4, %sum
620 %is.positive = icmp sgt i32 %sub, 0
621 br i1 %is.positive, label %if.true, label %if.false
624 switch i32 4, label %failure [
625 i32 100, label %backedge
626 i32 200, label %backedge
629 if.false: ; preds = %loop
633 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %if.true ], [ %sub, %if.true ]
634 %sum.next = add i32 %sum, %merge.phi
635 %loop.cond = icmp ne i32 %sum.next, 4
636 br i1 %loop.cond, label %loop, label %done
638 done: ; preds = %backedge
639 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
640 ret i32 %sum.next.lcssa
646 define i32 @test_multiple_pred_2(i1 %cond, i1 %cond2) {
647 ; CHECK-LABEL: @test_multiple_pred_2(
649 ; CHECK-NEXT: br label [[LOOP:%.*]]
651 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
652 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
653 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
654 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
656 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
658 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
660 ; CHECK-NEXT: br label [[BACKEDGE]]
662 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
664 ; CHECK-NEXT: br label [[BACKEDGE]]
666 ; CHECK-NEXT: br label [[BACKEDGE]]
668 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ [[SUB]], [[IF_TRUE_1]] ], [ [[SUB]], [[IF_TRUE_2]] ]
669 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
670 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
671 ; CHECK-NEXT: br label [[DONE:%.*]]
673 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
674 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
676 ; CHECK-NEXT: unreachable
682 loop: ; preds = %backedge, %entry
683 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
684 %sub = sub i32 4, %sum
685 %is.positive = icmp sgt i32 %sub, 0
686 br i1 %is.positive, label %if.true, label %if.false
689 br i1 %cond, label %if.true.1, label %if.true.2
697 if.false: ; preds = %loop
698 br i1 %cond2, label %if.false.1, label %if.false.2
707 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ %sub, %if.true.1 ], [ %sub, %if.true.2 ]
708 %sum.next = add i32 %sum, %merge.phi
709 %loop.cond = icmp ne i32 %sum.next, 4
710 br i1 %loop.cond, label %loop, label %done
712 done: ; preds = %backedge
713 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
714 ret i32 %sum.next.lcssa
720 define i32 @test_multiple_pred_undef_1(i1 %cond, i1 %cond2) {
721 ; CHECK-LABEL: @test_multiple_pred_undef_1(
723 ; CHECK-NEXT: br label [[LOOP:%.*]]
725 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
726 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
727 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
728 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
730 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
732 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
734 ; CHECK-NEXT: br label [[BACKEDGE]]
736 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
738 ; CHECK-NEXT: br label [[BACKEDGE]]
740 ; CHECK-NEXT: br label [[BACKEDGE]]
742 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ [[SUB]], [[IF_TRUE_1]] ], [ undef, [[IF_TRUE_2]] ]
743 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
744 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
745 ; CHECK-NEXT: br label [[DONE:%.*]]
747 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
748 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
750 ; CHECK-NEXT: unreachable
755 loop: ; preds = %backedge, %entry
756 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
757 %sub = sub i32 4, %sum
758 %is.positive = icmp sgt i32 %sub, 0
759 br i1 %is.positive, label %if.true, label %if.false
762 br i1 %cond, label %if.true.1, label %if.true.2
770 if.false: ; preds = %loop
771 br i1 %cond2, label %if.false.1, label %if.false.2
780 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ %sub, %if.true.1 ], [ undef, %if.true.2 ]
781 %sum.next = add i32 %sum, %merge.phi
782 %loop.cond = icmp ne i32 %sum.next, 4
783 br i1 %loop.cond, label %loop, label %done
785 done: ; preds = %backedge
786 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
787 ret i32 %sum.next.lcssa
793 define i32 @test_multiple_pred_undef_2(i1 %cond, i1 %cond2) {
794 ; CHECK-LABEL: @test_multiple_pred_undef_2(
796 ; CHECK-NEXT: br label [[LOOP:%.*]]
798 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
799 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
800 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
801 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
803 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
805 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
807 ; CHECK-NEXT: br label [[BACKEDGE]]
809 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
811 ; CHECK-NEXT: br label [[BACKEDGE]]
813 ; CHECK-NEXT: br label [[BACKEDGE]]
815 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ undef, [[IF_TRUE_1]] ], [ [[SUB]], [[IF_TRUE_2]] ]
816 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
817 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
818 ; CHECK-NEXT: br label [[DONE:%.*]]
820 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
821 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
823 ; CHECK-NEXT: unreachable
828 loop: ; preds = %backedge, %entry
829 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
830 %sub = sub i32 4, %sum
831 %is.positive = icmp sgt i32 %sub, 0
832 br i1 %is.positive, label %if.true, label %if.false
835 br i1 %cond, label %if.true.1, label %if.true.2
843 if.false: ; preds = %loop
844 br i1 %cond2, label %if.false.1, label %if.false.2
853 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ undef, %if.true.1 ], [ %sub, %if.true.2 ]
854 %sum.next = add i32 %sum, %merge.phi
855 %loop.cond = icmp ne i32 %sum.next, 4
856 br i1 %loop.cond, label %loop, label %done
858 done: ; preds = %backedge
859 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
860 ret i32 %sum.next.lcssa
866 define i32 @test_multiple_pred_undef_3(i1 %cond, i1 %cond2) {
867 ; CHECK-LABEL: @test_multiple_pred_undef_3(
869 ; CHECK-NEXT: br label [[LOOP:%.*]]
871 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
872 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
873 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
874 ; CHECK-NEXT: br i1 [[IS_POSITIVE]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
876 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_TRUE_2:%.*]]
878 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
880 ; CHECK-NEXT: br label [[BACKEDGE]]
882 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF_FALSE_1:%.*]], label [[IF_FALSE_2:%.*]]
884 ; CHECK-NEXT: br label [[BACKEDGE]]
886 ; CHECK-NEXT: br label [[BACKEDGE]]
888 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE_1]] ], [ 0, [[IF_FALSE_2]] ], [ undef, [[IF_TRUE_1]] ], [ undef, [[IF_TRUE_2]] ]
889 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
890 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
891 ; CHECK-NEXT: br label [[DONE:%.*]]
893 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
894 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
896 ; CHECK-NEXT: unreachable
901 loop: ; preds = %backedge, %entry
902 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
903 %sub = sub i32 4, %sum
904 %is.positive = icmp sgt i32 %sub, 0
905 br i1 %is.positive, label %if.true, label %if.false
908 br i1 %cond, label %if.true.1, label %if.true.2
916 if.false: ; preds = %loop
917 br i1 %cond2, label %if.false.1, label %if.false.2
926 %merge.phi = phi i32 [ 0, %if.false.1 ], [ 0, %if.false.2 ], [ undef, %if.true.1 ], [ undef, %if.true.2 ]
927 %sum.next = add i32 %sum, %merge.phi
928 %loop.cond = icmp ne i32 %sum.next, 4
929 br i1 %loop.cond, label %loop, label %done
931 done: ; preds = %backedge
932 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
933 ret i32 %sum.next.lcssa
939 ; TODO: We can break the backedge here.
940 define i32 @test_select(i32 %limit) {
941 ; CHECK-LABEL: @test_select(
943 ; CHECK-NEXT: [[LOOP_GUARD:%.*]] = icmp sgt i32 [[LIMIT:%.*]], 0
944 ; CHECK-NEXT: br i1 [[LOOP_GUARD]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
945 ; CHECK: loop.preheader:
946 ; CHECK-NEXT: br label [[LOOP:%.*]]
948 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ [[SUM_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
949 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[LIMIT]], [[SUM]]
950 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
951 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 0
952 ; CHECK-NEXT: [[SUM_NEXT]] = add i32 [[SUM]], [[SEL]]
953 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], [[LIMIT]]
954 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[DONE:%.*]]
956 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[LOOP]] ]
957 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
959 ; CHECK-NEXT: unreachable
962 %loop_guard = icmp sgt i32 %limit, 0
963 br i1 %loop_guard, label %loop, label %failure
965 loop: ; preds = %backedge, %entry
966 %sum = phi i32 [ 0, %entry ], [ %sum.next, %loop ]
967 %sub = sub i32 %limit, %sum
968 %is.positive = icmp sgt i32 %sub, 0
969 %sel = select i1 %is.positive, i32 %sub, i32 0
970 %sum.next = add i32 %sum, %sel
971 %loop.cond = icmp ne i32 %sum.next, %limit
972 br i1 %loop.cond, label %loop, label %done
974 done: ; preds = %backedge
975 %sum.next.lcssa = phi i32 [ %sum.next, %loop ]
976 ret i32 %sum.next.lcssa
982 define i32 @test_select_const(i32 %x) {
983 ; CHECK-LABEL: @test_select_const(
985 ; CHECK-NEXT: br label [[LOOP:%.*]]
987 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
988 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
989 ; CHECK-NEXT: [[IS_POSITIVE:%.*]] = icmp sgt i32 [[SUB]], 0
990 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[IS_POSITIVE]], i32 [[SUB]], i32 [[X:%.*]]
991 ; CHECK-NEXT: [[SEL_COND:%.*]] = icmp sgt i32 [[SEL]], 0
992 ; CHECK-NEXT: br i1 [[SEL_COND]], label [[BACKEDGE:%.*]], label [[IF_FALSE:%.*]]
994 ; CHECK-NEXT: br label [[BACKEDGE]]
996 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[IF_FALSE]] ], [ [[SUB]], [[LOOP]] ]
997 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
998 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
999 ; CHECK-NEXT: br label [[DONE:%.*]]
1001 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1002 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1007 loop: ; preds = %backedge, %entry
1008 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1009 %sub = sub i32 4, %sum
1010 %is.positive = icmp sgt i32 %sub, 0
1011 %sel = select i1 %is.positive, i32 %sub, i32 %x
1012 %sel.cond = icmp sgt i32 %sel, 0
1013 br i1 %sel.cond, label %backedge, label %if.false
1015 if.false: ; preds = %loop
1018 backedge: ; preds = %if.false, %loop
1019 %merge.phi = phi i32 [ 0, %if.false ], [ %sub, %loop ]
1020 %sum.next = add i32 %sum, %merge.phi
1021 %loop.cond = icmp ne i32 %sum.next, 4
1022 br i1 %loop.cond, label %loop, label %done
1024 done: ; preds = %backedge
1025 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1026 ret i32 %sum.next.lcssa
1033 ; Here switch will always jump to the default label
1034 define i32 @test_switch_ne_default() {
1035 ; CHECK-LABEL: @test_switch_ne_default(
1036 ; CHECK-NEXT: entry:
1037 ; CHECK-NEXT: br label [[LOOP:%.*]]
1039 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
1040 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
1041 ; CHECK-NEXT: switch i32 [[SUB]], label [[DEFAULT:%.*]] [
1042 ; CHECK-NEXT: i32 0, label [[ONZERO:%.*]]
1043 ; CHECK-NEXT: i32 1, label [[ONONE:%.*]]
1044 ; CHECK-NEXT: i32 2, label [[ONTWO:%.*]]
1047 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
1049 ; CHECK-NEXT: br label [[BACKEDGE]]
1051 ; CHECK-NEXT: br label [[BACKEDGE]]
1053 ; CHECK-NEXT: br label [[BACKEDGE]]
1055 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ [[SUB]], [[DEFAULT]] ], [ 0, [[ONZERO]] ], [ 1, [[ONONE]] ], [ 2, [[ONTWO]] ]
1056 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
1057 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
1058 ; CHECK-NEXT: br label [[DONE:%.*]]
1060 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1061 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1066 loop: ; preds = %backedge, %entry
1067 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1068 %sub = sub i32 4, %sum
1069 switch i32 %sub, label %default [
1070 i32 0, label %onzero
1075 default: ; preds = %loop
1078 onzero: ; preds = %loop
1081 onone: ; preds = %loop
1084 ontwo: ; preds = %loop
1087 backedge: ; preds = %ontwo, %onone, %onzero, %default
1088 %merge.phi = phi i32 [ %sub, %default ], [ 0, %onzero ], [ 1, %onone ], [ 2, %ontwo ]
1089 %sum.next = add i32 %sum, %merge.phi
1090 %loop.cond = icmp ne i32 %sum.next, 4
1091 br i1 %loop.cond, label %loop, label %done
1093 done: ; preds = %backedge
1094 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1095 ret i32 %sum.next.lcssa
1098 ; Here switch will always jump to the %ontwo label
1099 define i32 @test_switch_ne_one_case() {
1100 ; CHECK-LABEL: @test_switch_ne_one_case(
1101 ; CHECK-NEXT: entry:
1102 ; CHECK-NEXT: br label [[LOOP:%.*]]
1104 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
1105 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 4, [[SUM]]
1106 ; CHECK-NEXT: switch i32 [[SUB]], label [[DEFAULT:%.*]] [
1107 ; CHECK-NEXT: i32 0, label [[ONZERO:%.*]]
1108 ; CHECK-NEXT: i32 1, label [[ONONE:%.*]]
1109 ; CHECK-NEXT: i32 4, label [[ONTWO:%.*]]
1112 ; CHECK-NEXT: br label [[BACKEDGE:%.*]]
1114 ; CHECK-NEXT: br label [[BACKEDGE]]
1116 ; CHECK-NEXT: br label [[BACKEDGE]]
1118 ; CHECK-NEXT: br label [[BACKEDGE]]
1120 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 2, [[DEFAULT]] ], [ 0, [[ONZERO]] ], [ 1, [[ONONE]] ], [ [[SUB]], [[ONTWO]] ]
1121 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
1122 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 4
1123 ; CHECK-NEXT: br label [[DONE:%.*]]
1125 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1126 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1131 loop: ; preds = %backedge, %entry
1132 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1133 %sub = sub i32 4, %sum
1134 switch i32 %sub, label %default [
1135 i32 0, label %onzero
1140 default: ; preds = %loop
1143 onzero: ; preds = %loop
1146 onone: ; preds = %loop
1149 ontwo: ; preds = %loop
1152 backedge: ; preds = %ontwo, %onone, %onzero, %default
1153 %merge.phi = phi i32 [ 2, %default ], [ 0, %onzero ], [ 1, %onone ], [ %sub, %ontwo ]
1154 %sum.next = add i32 %sum, %merge.phi
1155 %loop.cond = icmp ne i32 %sum.next, 4
1156 br i1 %loop.cond, label %loop, label %done
1158 done: ; preds = %backedge
1159 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1160 ret i32 %sum.next.lcssa
1163 ; Here switch will always jump to the %backedge label, but there are two jumps to this label in switch
1164 define i32 @test_switch_ne_one_case_identical_jumps() {
1165 ; CHECK-LABEL: @test_switch_ne_one_case_identical_jumps(
1166 ; CHECK-NEXT: entry:
1167 ; CHECK-NEXT: br label [[LOOP:%.*]]
1169 ; CHECK-NEXT: [[SUM:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ]
1170 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 2, [[SUM]]
1171 ; CHECK-NEXT: switch i32 [[SUB]], label [[DEFAULT:%.*]] [
1172 ; CHECK-NEXT: i32 0, label [[FIRST_BLOCK:%.*]]
1173 ; CHECK-NEXT: i32 1, label [[BACKEDGE:%.*]]
1174 ; CHECK-NEXT: i32 2, label [[BACKEDGE]]
1177 ; CHECK-NEXT: br label [[BACKEDGE]]
1178 ; CHECK: first_block:
1179 ; CHECK-NEXT: br label [[BACKEDGE]]
1181 ; CHECK-NEXT: [[MERGE_PHI:%.*]] = phi i32 [ 0, [[DEFAULT]] ], [ 1, [[FIRST_BLOCK]] ], [ [[SUB]], [[LOOP]] ], [ [[SUB]], [[LOOP]] ]
1182 ; CHECK-NEXT: [[SUM_NEXT:%.*]] = add i32 [[SUM]], [[MERGE_PHI]]
1183 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ne i32 [[SUM_NEXT]], 2
1184 ; CHECK-NEXT: br label [[DONE:%.*]]
1186 ; CHECK-NEXT: [[SUM_NEXT_LCSSA:%.*]] = phi i32 [ [[SUM_NEXT]], [[BACKEDGE]] ]
1187 ; CHECK-NEXT: ret i32 [[SUM_NEXT_LCSSA]]
1192 loop: ; preds = %backedge, %entry
1193 %sum = phi i32 [ 0, %entry ], [ %sum.next, %backedge ]
1194 %sub = sub i32 2, %sum
1195 switch i32 %sub, label %default [
1196 i32 0, label %first_block
1197 i32 1, label %backedge
1198 i32 2, label %backedge
1201 default: ; preds = %loop
1204 first_block: ; preds = %loop
1207 backedge: ; preds = %first_block, %default, %loop, %loop
1208 %merge.phi = phi i32 [ 0, %default ], [ 1, %first_block ], [ %sub, %loop ], [ %sub, %loop ]
1209 %sum.next = add i32 %sum, %merge.phi
1210 %loop.cond = icmp ne i32 %sum.next, 2
1211 br i1 %loop.cond, label %loop, label %done
1213 done: ; preds = %backedge
1214 %sum.next.lcssa = phi i32 [ %sum.next, %backedge ]
1215 ret i32 %sum.next.lcssa
1218 @g = external global i32
1220 define void @ptr54615(ptr byval(i32) %arg) {
1221 ; CHECK-LABEL: @ptr54615(
1222 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
1224 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @g, [[ARG:%.*]]
1225 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_END:%.*]], label [[FOR_COND]]
1227 ; CHECK-NEXT: ret void
1232 %cmp = icmp eq ptr @g, %arg
1233 br i1 %cmp, label %for.end, label %for.cond