1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -instcombine | FileCheck %s
3 @A = extern_weak global i32, align 4
4 @B = extern_weak global i32, align 4
6 define i32 @foo(i1 %which) {
9 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
11 ; CHECK-NEXT: br label [[FINAL]]
13 ; CHECK-NEXT: [[USE2:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ select (i1 icmp eq (i32* @A, i32* @B), i32 2, i32 1), [[DELAY]] ]
14 ; CHECK-NEXT: ret i32 [[USE2]]
17 br i1 %which, label %final, label %delay
23 %use2 = phi i1 [ false, %entry ], [ icmp eq (i32* @A, i32* @B), %delay ]
24 %value = select i1 %use2, i32 2, i32 1
29 ; test folding of select into phi for vectors.
30 define <4 x i64> @vec1(i1 %which) {
33 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
35 ; CHECK-NEXT: br label [[FINAL]]
37 ; CHECK-NEXT: [[PHINODE:%.*]] = phi <4 x i64> [ zeroinitializer, [[ENTRY:%.*]] ], [ <i64 0, i64 0, i64 126, i64 127>, [[DELAY]] ]
38 ; CHECK-NEXT: ret <4 x i64> [[PHINODE]]
41 br i1 %which, label %final, label %delay
47 %phinode = phi <4 x i1> [ <i1 true, i1 true, i1 true, i1 true>, %entry ], [ <i1 true, i1 true, i1 false, i1 false>, %delay ]
48 %sel = select <4 x i1> %phinode, <4 x i64> zeroinitializer, <4 x i64> <i64 124, i64 125, i64 126, i64 127>
52 define <4 x i64> @vec2(i1 %which) {
55 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
57 ; CHECK-NEXT: br label [[FINAL]]
59 ; CHECK-NEXT: [[PHINODE:%.*]] = phi <4 x i64> [ <i64 124, i64 125, i64 126, i64 127>, [[ENTRY:%.*]] ], [ <i64 0, i64 125, i64 0, i64 127>, [[DELAY]] ]
60 ; CHECK-NEXT: ret <4 x i64> [[PHINODE]]
63 br i1 %which, label %final, label %delay
69 %phinode = phi <4 x i1> [ <i1 false, i1 false, i1 false, i1 false>, %entry ], [ <i1 true, i1 false, i1 true, i1 false>, %delay ]
70 %sel = select <4 x i1> %phinode, <4 x i64> zeroinitializer, <4 x i64> <i64 124, i64 125, i64 126, i64 127>
75 ; Insert the generated select into the same block as the incoming phi value.
76 ; phi has constant vectors along with a single non-constant vector as operands.
77 define <2 x i8> @vec3(i1 %cond1, i1 %cond2, <2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {
80 ; CHECK-NEXT: [[PHITMP1:%.*]] = shufflevector <2 x i8> [[Z:%.*]], <2 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 3>
81 ; CHECK-NEXT: br i1 [[COND1:%.*]], label [[IF1:%.*]], label [[ELSE:%.*]]
83 ; CHECK-NEXT: [[PHITMP2:%.*]] = shufflevector <2 x i8> [[Y]], <2 x i8> [[Z]], <2 x i32> <i32 0, i32 3>
84 ; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF2:%.*]], label [[ELSE]]
86 ; CHECK-NEXT: [[PHITMP:%.*]] = select <2 x i1> [[X:%.*]], <2 x i8> [[Y]], <2 x i8> [[Z]]
87 ; CHECK-NEXT: br label [[ELSE]]
89 ; CHECK-NEXT: [[PHI:%.*]] = phi <2 x i8> [ [[PHITMP]], [[IF2]] ], [ [[PHITMP1]], [[ENTRY:%.*]] ], [ [[PHITMP2]], [[IF1]] ]
90 ; CHECK-NEXT: ret <2 x i8> [[PHI]]
93 br i1 %cond1, label %if1, label %else
96 br i1 %cond2, label %if2, label %else
102 %phi = phi <2 x i1> [ %x, %if2 ], [ <i1 0, i1 1>, %entry ], [ <i1 1, i1 0>, %if1 ]
103 %sel = select <2 x i1> %phi, <2 x i8> %y, <2 x i8> %z