1 ; This test makes sure that these instructions are properly eliminated.
3 ; RUN: opt < %s -instcombine -S | FileCheck %s
5 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128:n8:16:32:64"
7 define i32 @test1(i32 %A, i1 %b) {
9 br i1 %b, label %BB1, label %BB2
12 ; Combine away one argument PHI nodes
13 %B = phi i32 [ %A, %BB0 ]
18 ; CHECK-LABEL: @test1(
20 ; CHECK-NEXT: ret i32 %A
23 define i32 @test2(i32 %A, i1 %b) {
25 br i1 %b, label %BB1, label %BB2
31 ; Combine away PHI nodes with same values
32 %B = phi i32 [ %A, %BB0 ], [ %A, %BB1 ]
34 ; CHECK-LABEL: @test2(
36 ; CHECK-NEXT: ret i32 %A
39 define i32 @test3(i32 %A, i1 %b) {
44 ; PHI has same value always.
45 %B = phi i32 [ %A, %BB0 ], [ %B, %Loop ]
46 br i1 %b, label %Loop, label %Exit
50 ; CHECK-LABEL: @test3(
52 ; CHECK-NEXT: ret i32 %A
55 define i32 @test4(i1 %b) {
60 Loop: ; preds = %L2, %Loop
61 ; PHI has same value always.
62 %B = phi i32 [ %B, %L2 ], [ %B, %Loop ]
63 br i1 %b, label %L2, label %Loop
67 ; CHECK-LABEL: @test4(
69 ; CHECK-NEXT: br i1 %b
72 define i32 @test5(i32 %A, i1 %b) {
76 Loop: ; preds = %Loop, %BB0
77 ; PHI has same value always.
78 %B = phi i32 [ %A, %BB0 ], [ undef, %Loop ]
79 br i1 %b, label %Loop, label %Exit
83 ; CHECK-LABEL: @test5(
85 ; CHECK-NEXT: br i1 %b
87 ; CHECK-NEXT: ret i32 %A
90 define i32 @test6(i16 %A, i1 %b) {
92 %X = zext i16 %A to i32
93 br i1 %b, label %BB1, label %BB2
96 %Y = zext i16 %A to i32
100 ;; Suck casts into phi
101 %B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
103 ; CHECK-LABEL: @test6(
105 ; CHECK: zext i16 %A to i32
106 ; CHECK-NEXT: ret i32
109 define i32 @test7(i32 %A, i1 %b) {
113 Loop: ; preds = %Loop, %BB0
115 %B = phi i32 [ %A, %BB0 ], [ %C, %Loop ]
117 br i1 %b, label %Loop, label %Exit
119 Exit: ; preds = %Loop
121 ; CHECK-LABEL: @test7(
123 ; CHECK-NEXT: br i1 %b
126 define i32* @test8({ i32, i32 } *%A, i1 %b) {
128 %X = getelementptr inbounds { i32, i32 }, { i32, i32 } *%A, i32 0, i32 1
129 br i1 %b, label %BB1, label %BB2
132 %Y = getelementptr { i32, i32 }, { i32, i32 } *%A, i32 0, i32 1
136 ;; Suck GEPs into phi
137 %B = phi i32* [ %X, %BB0 ], [ %Y, %BB1 ]
139 ; CHECK-LABEL: @test8(
142 ; CHECK-NEXT: %B = getelementptr { i32, i32 }, { i32, i32 }* %A
143 ; CHECK-NEXT: ret i32* %B
146 define i32 @test9(i32* %A, i32* %B) {
148 %c = icmp eq i32* %A, null
149 br i1 %c, label %bb1, label %bb
152 %C = load i32, i32* %B, align 1
156 %D = load i32, i32* %A, align 1
160 %E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
162 ; CHECK-LABEL: @test9(
164 ; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
165 ; CHECK-NEXT: %E = load i32, i32* %{{[^,]*}}, align 1
166 ; CHECK-NEXT: ret i32 %E
170 define i32 @test10(i32* %A, i32* %B) {
172 %c = icmp eq i32* %A, null
173 br i1 %c, label %bb1, label %bb
176 %C = load i32, i32* %B, align 16
180 %D = load i32, i32* %A, align 32
184 %E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
186 ; CHECK-LABEL: @test10(
188 ; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
189 ; CHECK-NEXT: %E = load i32, i32* %{{[^,]*}}, align 16
190 ; CHECK-NEXT: ret i32 %E
195 declare i1 @test11a()
197 define i1 @test11() {
200 %i = ptrtoint i32* %a to i64
201 %b = call i1 @test11a()
202 br i1 %b, label %one, label %two
205 %x = phi i64 [%i, %entry], [%y, %two]
206 %c = call i1 @test11a()
207 br i1 %c, label %two, label %end
210 %y = phi i64 [%i, %entry], [%x, %one]
211 %d = call i1 @test11a()
212 br i1 %d, label %one, label %end
215 %f = phi i64 [ %x, %one], [%y, %two]
216 ; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
217 ; even though %f must equal %i at this point
218 %g = inttoptr i64 %f to i32*
219 store i32 10, i32* %g
220 %z = call i1 @test11a()
222 ; CHECK-LABEL: @test11(
228 define i64 @test12(i1 %cond, i8* %Ptr, i64 %Val) {
230 %tmp41 = ptrtoint i8* %Ptr to i64
231 %tmp42 = zext i64 %tmp41 to i128
232 br i1 %cond, label %end, label %two
235 %tmp36 = zext i64 %Val to i128 ; <i128> [#uses=1]
236 %tmp37 = shl i128 %tmp36, 64 ; <i128> [#uses=1]
237 %ins39 = or i128 %tmp42, %tmp37 ; <i128> [#uses=1]
241 %tmp869.0 = phi i128 [ %tmp42, %entry ], [ %ins39, %two ]
242 %tmp32 = trunc i128 %tmp869.0 to i64 ; <i64> [#uses=1]
243 %tmp29 = lshr i128 %tmp869.0, 64 ; <i128> [#uses=1]
244 %tmp30 = trunc i128 %tmp29 to i64 ; <i64> [#uses=1]
246 %tmp2 = add i64 %tmp32, %tmp30
248 ; CHECK-LABEL: @test12(
251 ; CHECK-NEXT: phi i64 [ 0, %entry ], [ %Val, %two ]
256 declare void @test13f(double, i32)
258 define void @test13(i1 %cond, i32 %V1, double %Vald) {
260 %tmp42 = zext i32 %V1 to i128
261 br i1 %cond, label %end, label %two
264 %Val = bitcast double %Vald to i64
265 %tmp36 = zext i64 %Val to i128 ; <i128> [#uses=1]
266 %tmp37 = shl i128 %tmp36, 64 ; <i128> [#uses=1]
267 %ins39 = or i128 %tmp42, %tmp37 ; <i128> [#uses=1]
271 %tmp869.0 = phi i128 [ %tmp42, %entry ], [ %ins39, %two ]
272 %tmp32 = trunc i128 %tmp869.0 to i32
273 %tmp29 = lshr i128 %tmp869.0, 64 ; <i128> [#uses=1]
274 %tmp30 = trunc i128 %tmp29 to i64 ; <i64> [#uses=1]
275 %tmp31 = bitcast i64 %tmp30 to double
277 call void @test13f(double %tmp31, i32 %tmp32)
279 ; CHECK-LABEL: @test13(
282 ; CHECK-NEXT: phi double [ 0.000000e+00, %entry ], [ %Vald, %two ]
283 ; CHECK-NEXT: call void @test13f(double {{[^,]*}}, i32 %V1)
287 define i640 @test14a(i320 %A, i320 %B, i1 %b1) {
289 %a = zext i320 %A to i640
290 %b = zext i320 %B to i640
294 %C = phi i640 [ %a, %BB0 ], [ %b, %Loop ]
295 br i1 %b1, label %Loop, label %Exit
297 Exit: ; preds = %Loop
299 ; CHECK-LABEL: @test14a(
301 ; CHECK-NEXT: phi i320
304 define i160 @test14b(i320 %A, i320 %B, i1 %b1) {
306 %a = trunc i320 %A to i160
307 %b = trunc i320 %B to i160
311 %C = phi i160 [ %a, %BB0 ], [ %b, %Loop ]
312 br i1 %b1, label %Loop, label %Exit
314 Exit: ; preds = %Loop
316 ; CHECK-LABEL: @test14b(
318 ; CHECK-NEXT: phi i160
321 declare i64 @test15a(i64)
323 define i64 @test15b(i64 %A, i1 %b) {
324 ; CHECK-LABEL: @test15b(
326 %i0 = zext i64 %A to i128
327 %i1 = shl i128 %i0, 64
328 %i = or i128 %i1, %i0
329 br i1 %b, label %one, label %two
331 ; CHECK-NEXT: br i1 %b
334 %x = phi i128 [%i, %entry], [%y, %two]
335 %x1 = lshr i128 %x, 64
336 %x2 = trunc i128 %x1 to i64
337 %c = call i64 @test15a(i64 %x2)
338 %c1 = zext i64 %c to i128
342 ; CHECK-NEXT: phi i64
343 ; CHECK-NEXT: %c = call i64 @test15a
346 %y = phi i128 [%i, %entry], [%c1, %one]
347 %y1 = lshr i128 %y, 64
348 %y2 = trunc i128 %y1 to i64
349 %d = call i64 @test15a(i64 %y2)
350 %d1 = trunc i64 %d to i1
351 br i1 %d1, label %one, label %end
354 ; CHECK-NEXT: phi i64
355 ; CHECK-NEXT: phi i64
356 ; CHECK-NEXT: %d = call i64 @test15a
359 %g = trunc i128 %y to i64
362 ; CHECK-NEXT: ret i64
365 ; PR6512 - Shouldn't merge loads from different addr spaces.
366 define i32 @test16(i32 addrspace(1)* %pointer1, i32 %flag, i32* %pointer2)
369 %retval = alloca i32, align 4 ; <i32*> [#uses=2]
370 %pointer1.addr = alloca i32 addrspace(1)*, align 4 ; <i32 addrspace(1)**>
371 %flag.addr = alloca i32, align 4 ; <i32*> [#uses=2]
372 %pointer2.addr = alloca i32*, align 4 ; <i32**> [#uses=2]
373 %res = alloca i32, align 4 ; <i32*> [#uses=4]
374 store i32 addrspace(1)* %pointer1, i32 addrspace(1)** %pointer1.addr
375 store i32 %flag, i32* %flag.addr
376 store i32* %pointer2, i32** %pointer2.addr
377 store i32 10, i32* %res
378 %tmp = load i32, i32* %flag.addr ; <i32> [#uses=1]
379 %tobool = icmp ne i32 %tmp, 0 ; <i1> [#uses=1]
380 br i1 %tobool, label %if.then, label %if.else
382 return: ; preds = %if.end
383 %tmp7 = load i32, i32* %retval ; <i32> [#uses=1]
386 if.end: ; preds = %if.else, %if.then
387 %tmp6 = load i32, i32* %res ; <i32> [#uses=1]
388 store i32 %tmp6, i32* %retval
391 if.then: ; preds = %entry
392 %tmp1 = load i32 addrspace(1)*, i32 addrspace(1)** %pointer1.addr ; <i32 addrspace(1)*>
393 %arrayidx = getelementptr i32, i32 addrspace(1)* %tmp1, i32 0 ; <i32 addrspace(1)*> [#uses=1]
394 %tmp2 = load i32, i32 addrspace(1)* %arrayidx ; <i32> [#uses=1]
395 store i32 %tmp2, i32* %res
398 if.else: ; preds = %entry
399 %tmp3 = load i32*, i32** %pointer2.addr ; <i32*> [#uses=1]
400 %arrayidx4 = getelementptr i32, i32* %tmp3, i32 0 ; <i32*> [#uses=1]
401 %tmp5 = load i32, i32* %arrayidx4 ; <i32> [#uses=1]
402 store i32 %tmp5, i32* %res
408 ; CHECK-LABEL: @test17(
409 define i32 @test17(i1 %a) {
411 br i1 %a, label %bb1, label %bb2
413 bb1: ; preds = %entry
414 %0 = tail call i32 @ext() ; <i32> [#uses=1]
417 bb2: ; preds = %bb1, %entry
418 %cond = phi i1 [ true, %bb1 ], [ false, %entry ] ; <i1> [#uses=1]
419 ; CHECK-NOT: %val = phi i32 [ %0, %bb1 ], [ 0, %entry ]
420 %val = phi i32 [ %0, %bb1 ], [ 0, %entry ] ; <i32> [#uses=1]
421 %res = select i1 %cond, i32 %val, i32 0 ; <i32> [#uses=1]
422 ; CHECK: ret i32 %cond
426 define i1 @test18(i1 %cond) {
429 br i1 %cond, label %true, label %false
435 %ptr = phi i32* [ %zero, %true ] , [ %one, %false ]
436 %isnull = icmp eq i32* %ptr, null
438 ; CHECK-LABEL: @test18(
439 ; CHECK: ret i1 false
442 define i1 @test19(i1 %cond, double %x) {
443 br i1 %cond, label %true, label %false
449 %p = phi double [ %x, %true ], [ 0x7FF0000000000000, %false ]; RHS = +infty
450 %cmp = fcmp ule double %x, %p
452 ; CHECK-LABEL: @test19(
456 define i1 @test20(i1 %cond) {
460 br i1 %cond, label %true, label %false
466 %p = phi i32* [ %a, %true ], [ %b, %false ]
467 %r = icmp eq i32* %p, %c
469 ; CHECK-LABEL: @test20(
470 ; CHECK: ret i1 false
473 define i1 @test21(i1 %c1, i1 %c2) {
477 br i1 %c1, label %true, label %false
483 %p = phi i32* [ %a, %true ], [ %b, %false ], [ %p, %loop ]
484 %r = icmp eq i32* %p, %c
485 br i1 %c2, label %ret, label %loop
488 ; CHECK-LABEL: @test21(
489 ; CHECK: ret i1 false
492 define void @test22() {
493 ; CHECK-LABEL: @test22(
497 %phi = phi i32 [ 0, %entry ], [ %y, %loop ]
500 %e = icmp eq i32 %o, %y
501 br i1 %e, label %loop, label %ret
507 define i32 @test23(i32 %A, i1 %b, i32 * %P) {
511 Loop: ; preds = %Loop, %BB0
512 ; PHI has same value always.
513 %B = phi i32 [ %A, %BB0 ], [ 42, %Loop ]
515 store i32 %D, i32* %P
516 br i1 %b, label %Loop, label %Exit
518 Exit: ; preds = %Loop
521 ; CHECK-LABEL: @test23(
522 ; CHECK: %phitmp = add i32 %A, 19
524 ; CHECK-NEXT: %B = phi i32 [ %phitmp, %BB0 ], [ 61, %Loop ]
526 ; CHECK-NEXT: ret i32 %B
529 define i32 @test24(i32 %A, i1 %cond) {
531 %X = add nuw nsw i32 %A, 1
532 br i1 %cond, label %BB1, label %BB2
535 %Y = add nuw i32 %A, 1
539 %C = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
541 ; CHECK-LABEL: @test24(
544 ; CHECK-NEXT: %C = add nuw i32 %A, 1
545 ; CHECK-NEXT: ret i32 %C
548 ; Same as test11, but used to be missed due to a bug.
549 declare i1 @test25a()
551 define i1 @test25() {
554 %i = ptrtoint i32* %a to i64
555 %b = call i1 @test25a()
556 br i1 %b, label %one, label %two
559 %x = phi i64 [%y, %two], [%i, %entry]
560 %c = call i1 @test25a()
561 br i1 %c, label %two, label %end
564 %y = phi i64 [%x, %one], [%i, %entry]
565 %d = call i1 @test25a()
566 br i1 %d, label %one, label %end
569 %f = phi i64 [ %x, %one], [%y, %two]
570 ; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
571 ; even though %f must equal %i at this point
572 %g = inttoptr i64 %f to i32*
573 store i32 10, i32* %g
574 %z = call i1 @test25a()
576 ; CHECK-LABEL: @test25(
581 declare i1 @test26a()
583 define i1 @test26(i32 %n) {
586 %i = ptrtoint i32* %a to i64
587 %b = call i1 @test26a()
591 %x = phi i64 [%y, %two], [%w, %three], [%i, %entry]
592 %c = call i1 @test26a()
593 switch i32 %n, label %end [
599 %y = phi i64 [%x, %one], [%w, %three]
600 %d = call i1 @test26a()
601 switch i32 %n, label %end [
607 %w = phi i64 [%y, %two], [%x, %one]
608 %e = call i1 @test26a()
609 br i1 %e, label %one, label %two
612 %f = phi i64 [ %x, %one], [%y, %two]
613 ; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
614 ; even though %f must equal %i at this point
615 %g = inttoptr i64 %f to i32*
616 store i32 10, i32* %g
617 %z = call i1 @test26a()
619 ; CHECK-LABEL: @test26(
624 ; CHECK-LABEL: @test27(
625 ; CHECK: ret i32 undef
626 define i32 @test27(i1 %b) {
630 %y = phi i32 [ undef, %entry ]
634 ; We should be able to fold the zexts to the other side of the phi
635 ; even though there's a constant value input to the phi. This is
636 ; because we can shrink that constant to the smaller phi type.
638 define i1 @PR24766(i8 %x1, i8 %x2, i8 %condition) {
640 %conv = sext i8 %condition to i32
641 switch i32 %conv, label %epilog [
647 %cmp1 = icmp eq i8 %x1, %x2
648 %frombool1 = zext i1 %cmp1 to i8
652 %cmp2 = icmp sle i8 %x1, %x2
653 %frombool2 = zext i1 %cmp2 to i8
657 %conditionMet = phi i8 [ 0, %entry ], [ %frombool2, %sw2 ], [ %frombool1, %sw1 ]
658 %tobool = icmp ne i8 %conditionMet, 0
661 ; CHECK-LABEL: @PR24766(
662 ; CHECK: %[[RES:.*]] = phi i1 [ false, %entry ], [ %cmp2, %sw2 ], [ %cmp1, %sw1 ]
663 ; CHECK-NEXT: ret i1 %[[RES]]
666 ; Same as above (a phi with more than 2 operands), but no constants
668 define i1 @PR24766_no_constants(i8 %x1, i8 %x2, i8 %condition, i1 %another_condition) {
670 %frombool0 = zext i1 %another_condition to i8
671 %conv = sext i8 %condition to i32
672 switch i32 %conv, label %epilog [
678 %cmp1 = icmp eq i8 %x1, %x2
679 %frombool1 = zext i1 %cmp1 to i8
683 %cmp2 = icmp sle i8 %x1, %x2
684 %frombool2 = zext i1 %cmp2 to i8
688 %conditionMet = phi i8 [ %frombool0, %entry ], [ %frombool2, %sw2 ], [ %frombool1, %sw1 ]
689 %tobool = icmp ne i8 %conditionMet, 0
692 ; CHECK-LABEL: @PR24766_no_constants(
693 ; CHECK: %[[RES:.*]] = phi i1 [ %another_condition, %entry ], [ %cmp2, %sw2 ], [ %cmp1, %sw1 ]
694 ; CHECK-NEXT: ret i1 %[[RES]]
697 ; Same as above (a phi with more than 2 operands), but two constants
699 define i1 @PR24766_two_constants(i8 %x1, i8 %x2, i8 %condition) {
701 %conv = sext i8 %condition to i32
702 switch i32 %conv, label %epilog [
708 %cmp1 = icmp eq i8 %x1, %x2
709 %frombool1 = zext i1 %cmp1 to i8
713 %cmp2 = icmp sle i8 %x1, %x2
714 %frombool2 = zext i1 %cmp2 to i8
718 %conditionMet = phi i8 [ 0, %entry ], [ 1, %sw2 ], [ %frombool1, %sw1 ]
719 %tobool = icmp ne i8 %conditionMet, 0
722 ; CHECK-LABEL: @PR24766_two_constants(
723 ; CHECK: %[[RES:.*]] = phi i1 [ false, %entry ], [ true, %sw2 ], [ %cmp1, %sw1 ]
724 ; CHECK-NEXT: ret i1 %[[RES]]
727 ; Same as above (a phi with more than 2 operands), but two constants and two variables
729 define i1 @PR24766_two_constants_two_var(i8 %x1, i8 %x2, i8 %condition) {
731 %conv = sext i8 %condition to i32
732 switch i32 %conv, label %epilog [
739 %cmp1 = icmp eq i8 %x1, %x2
740 %frombool1 = zext i1 %cmp1 to i8
744 %cmp2 = icmp sle i8 %x1, %x2
745 %frombool2 = zext i1 %cmp2 to i8
749 %cmp3 = icmp sge i8 %x1, %x2
750 %frombool3 = zext i1 %cmp3 to i8
754 %conditionMet = phi i8 [ 0, %entry ], [ %frombool2, %sw2 ], [ %frombool1, %sw1 ], [ 1, %sw3 ]
755 %tobool = icmp ne i8 %conditionMet, 0
758 ; CHECK-LABEL: @PR24766_two_constants_two_var(
759 ; CHECK: %[[RES:.*]] = phi i1 [ false, %entry ], [ %cmp2, %sw2 ], [ %cmp1, %sw1 ], [ true, %sw3 ]
760 ; CHECK-NEXT: ret i1 %[[RES]]
763 ; CHECK-LABEL: phi_allnonzeroconstant
765 ; CHECK: ret i1 false
766 define i1 @phi_allnonzeroconstant(i1 %c, i32 %a, i32 %b) {
768 br i1 %c, label %if.then, label %if.else
770 if.then: ; preds = %entry
773 if.else: ; preds = %entry
778 if.end: ; preds = %if.else, %if.then
779 %x.0 = phi i32 [ 1, %if.then ], [ 2, %if.else ]
780 %or = or i32 %x.0, %a
781 %cmp1 = icmp eq i32 %or, 0
785 declare void @dummy()
787 ; CHECK-LABEL: @phi_knownnonzero_eq
788 ; CHECK-LABEL: if.then:
790 ; CHECK-LABEL: if.end:
791 ; CHECK: phi i32 [ 1, %if.then ]
792 define i1 @phi_knownnonzero_eq(i32 %n, i32 %s, i32* nocapture readonly %P) {
794 %tobool = icmp slt i32 %n, %s
795 br i1 %tobool, label %if.end, label %if.then
797 if.then: ; preds = %entry
798 %0 = load i32, i32* %P
799 %cmp = icmp eq i32 %n, %0
800 %1 = select i1 %cmp, i32 1, i32 2
803 if.end: ; preds = %entry, %if.then
804 %a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ]
805 %cmp1 = icmp eq i32 %a.0, 0
809 ; CHECK-LABEL: @phi_knownnonzero_ne
810 ; CHECK-LABEL: if.then:
812 ; CHECK-LABEL: if.end:
813 ; CHECK: phi i32 [ 1, %if.then ]
814 define i1 @phi_knownnonzero_ne(i32 %n, i32 %s, i32* nocapture readonly %P) {
816 %tobool = icmp slt i32 %n, %s
817 br i1 %tobool, label %if.end, label %if.then
819 if.then: ; preds = %entry
820 %0 = load i32, i32* %P
821 %cmp = icmp eq i32 %n, %0
822 %1 = select i1 %cmp, i32 1, i32 2
825 if.end: ; preds = %entry, %if.then
826 %a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ]
827 %cmp1 = icmp ne i32 %a.0, 0
831 ; CHECK-LABEL: @phi_knownnonzero_eq_2
832 ; CHECK-LABEL: if.then:
834 ; CHECK-LABEL: if.end:
835 ; CHECK: phi i32 [ 2, %if.else ]
836 define i1 @phi_knownnonzero_eq_2(i32 %n, i32 %s, i32* nocapture readonly %P) {
838 %tobool = icmp slt i32 %n, %s
839 br i1 %tobool, label %if.then, label %if.end
842 %tobool2 = icmp slt i32 %n, %s
843 br i1 %tobool2, label %if.else, label %if.end
845 if.else: ; preds = %entry
846 %0 = load i32, i32* %P
847 %cmp = icmp eq i32 %n, %0
848 %1 = select i1 %cmp, i32 1, i32 2
851 if.end: ; preds = %entry, %if.then
852 %a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then]
853 %cmp1 = icmp eq i32 %a.0, 0
857 ; CHECK-LABEL: @phi_knownnonzero_ne_2
858 ; CHECK-LABEL: if.then:
860 ; CHECK-LABEL: if.end:
861 ; CHECK: phi i32 [ 2, %if.else ]
862 define i1 @phi_knownnonzero_ne_2(i32 %n, i32 %s, i32* nocapture readonly %P) {
864 %tobool = icmp slt i32 %n, %s
865 br i1 %tobool, label %if.then, label %if.end
868 %tobool2 = icmp slt i32 %n, %s
869 br i1 %tobool2, label %if.else, label %if.end
871 if.else: ; preds = %entry
872 %0 = load i32, i32* %P
873 %cmp = icmp eq i32 %n, %0
874 %1 = select i1 %cmp, i32 1, i32 2
877 if.end: ; preds = %entry, %if.then
878 %a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then]
879 %cmp1 = icmp ne i32 %a.0, 0