1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i32 @const(i1 %cond) {
6 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
8 ; CHECK-NEXT: br label [[C:%.*]]
10 ; CHECK-NEXT: br label [[C]]
12 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ 1, [[B]] ]
13 ; CHECK-NEXT: ret i32 [[Y]]
15 br i1 %cond, label %A, label %B
21 %y = phi i32 [0, %A], [1, %B]
26 define <2 x i32> @vec(i1 %cond) {
28 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
30 ; CHECK-NEXT: br label [[C:%.*]]
32 ; CHECK-NEXT: br label [[C]]
34 ; CHECK-NEXT: [[Y:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[A]] ], [ <i32 2, i32 3>, [[B]] ]
35 ; CHECK-NEXT: ret <2 x i32> [[Y]]
37 br i1 %cond, label %A, label %B
43 %y = phi <2 x i32> [<i32 0, i32 1>, %A], [<i32 2, i32 3>, %B]
44 %y.fr = freeze <2 x i32> %y
48 define <2 x i32> @vec_undef(i1 %cond) {
49 ; CHECK-LABEL: @vec_undef(
50 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
52 ; CHECK-NEXT: br label [[C:%.*]]
54 ; CHECK-NEXT: br label [[C]]
56 ; CHECK-NEXT: [[Y:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[A]] ], [ <i32 2, i32 0>, [[B]] ]
57 ; CHECK-NEXT: ret <2 x i32> [[Y]]
59 br i1 %cond, label %A, label %B
65 %y = phi <2 x i32> [<i32 0, i32 1>, %A], [<i32 2, i32 undef>, %B]
66 %y.fr = freeze <2 x i32> %y
70 define i32 @one(i1 %cond, i32 %x) {
72 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
74 ; CHECK-NEXT: br label [[C:%.*]]
76 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 [[X:%.*]]
77 ; CHECK-NEXT: br label [[C]]
79 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ [[TMP1]], [[B]] ]
80 ; CHECK-NEXT: ret i32 [[Y]]
82 br i1 %cond, label %A, label %B
88 %y = phi i32 [0, %A], [%x, %B]
93 define i32 @two(i1 %cond, i32 %x, i32 %x2) {
95 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
97 ; CHECK-NEXT: br label [[C:%.*]]
99 ; CHECK-NEXT: br label [[C]]
101 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ [[X:%.*]], [[A]] ], [ [[X2:%.*]], [[B]] ]
102 ; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
103 ; CHECK-NEXT: ret i32 [[Y_FR]]
105 br i1 %cond, label %A, label %B
111 %y = phi i32 [%x, %A], [%x2, %B]
112 %y.fr = freeze i32 %y
116 define i32 @two_undef(i8 %cond, i32 %x) {
117 ; CHECK-LABEL: @two_undef(
118 ; CHECK-NEXT: switch i8 [[COND:%.*]], label [[A:%.*]] [
119 ; CHECK-NEXT: i8 0, label [[B:%.*]]
120 ; CHECK-NEXT: i8 1, label [[C:%.*]]
123 ; CHECK-NEXT: br label [[D:%.*]]
125 ; CHECK-NEXT: br label [[D]]
127 ; CHECK-NEXT: br label [[D]]
129 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ undef, [[A]] ], [ [[X:%.*]], [[B]] ], [ 0, [[C]] ]
130 ; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
131 ; CHECK-NEXT: ret i32 [[Y_FR]]
133 switch i8 %cond, label %A [
144 %y = phi i32 [undef, %A], [%x, %B], [0, %C]
145 %y.fr = freeze i32 %y
149 define i32 @one_undef(i8 %cond) {
150 ; CHECK-LABEL: @one_undef(
151 ; CHECK-NEXT: switch i8 [[COND:%.*]], label [[A:%.*]] [
152 ; CHECK-NEXT: i8 0, label [[B:%.*]]
153 ; CHECK-NEXT: i8 1, label [[C:%.*]]
156 ; CHECK-NEXT: br label [[D:%.*]]
158 ; CHECK-NEXT: br label [[D]]
160 ; CHECK-NEXT: br label [[D]]
162 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
163 ; CHECK-NEXT: ret i32 [[Y]]
165 switch i8 %cond, label %A [
176 %y = phi i32 [undef, %A], [32, %B], [0, %C]
177 %y.fr = freeze i32 %y
183 define i32 @one_constexpr(i8 %cond, i32 %x) {
184 ; CHECK-LABEL: @one_constexpr(
185 ; CHECK-NEXT: switch i8 [[COND:%.*]], label [[A:%.*]] [
186 ; CHECK-NEXT: i8 0, label [[B:%.*]]
187 ; CHECK-NEXT: i8 1, label [[C:%.*]]
190 ; CHECK-NEXT: [[TMP1:%.*]] = freeze i32 ptrtoint (ptr getelementptr inbounds (i8, ptr @glb, i64 2) to i32)
191 ; CHECK-NEXT: br label [[D:%.*]]
193 ; CHECK-NEXT: br label [[D]]
195 ; CHECK-NEXT: br label [[D]]
197 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ [[TMP1]], [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
198 ; CHECK-NEXT: ret i32 [[Y]]
200 switch i8 %cond, label %A [
211 %y = phi i32 [ptrtoint (ptr getelementptr inbounds (i8, ptr @glb, i64 2) to i32), %A], [32, %B], [0, %C]
212 %y.fr = freeze i32 %y