1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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: [[PHI_FR:%.*]] = freeze <2 x i32> <i32 2, i32 undef>
55 ; CHECK-NEXT: br label [[C]]
57 ; CHECK-NEXT: [[Y:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[A]] ], [ [[PHI_FR]], [[B]] ]
58 ; CHECK-NEXT: ret <2 x i32> [[Y]]
60 br i1 %cond, label %A, label %B
66 %y = phi <2 x i32> [<i32 0, i32 1>, %A], [<i32 2, i32 undef>, %B]
67 %y.fr = freeze <2 x i32> %y
71 define i32 @one(i1 %cond, i32 %x) {
73 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
75 ; CHECK-NEXT: br label [[C:%.*]]
77 ; CHECK-NEXT: [[PHI_FR:%.*]] = freeze i32 [[X:%.*]]
78 ; CHECK-NEXT: br label [[C]]
80 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ [[PHI_FR]], [[B]] ]
81 ; CHECK-NEXT: ret i32 [[Y]]
83 br i1 %cond, label %A, label %B
89 %y = phi i32 [0, %A], [%x, %B]
94 define i32 @two(i1 %cond, i32 %x, i32 %x2) {
96 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
98 ; CHECK-NEXT: br label [[C:%.*]]
100 ; CHECK-NEXT: br label [[C]]
102 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ [[X:%.*]], [[A]] ], [ [[X2:%.*]], [[B]] ]
103 ; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
104 ; CHECK-NEXT: ret i32 [[Y_FR]]
106 br i1 %cond, label %A, label %B
112 %y = phi i32 [%x, %A], [%x2, %B]
113 %y.fr = freeze i32 %y
117 define i32 @two_undef(i8 %cond, i32 %x) {
118 ; CHECK-LABEL: @two_undef(
119 ; CHECK-NEXT: switch i8 [[COND:%.*]], label [[A:%.*]] [
120 ; CHECK-NEXT: i8 0, label [[B:%.*]]
121 ; CHECK-NEXT: i8 1, label [[C:%.*]]
124 ; CHECK-NEXT: br label [[D:%.*]]
126 ; CHECK-NEXT: br label [[D]]
128 ; CHECK-NEXT: br label [[D]]
130 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ undef, [[A]] ], [ [[X:%.*]], [[B]] ], [ 0, [[C]] ]
131 ; CHECK-NEXT: [[Y_FR:%.*]] = freeze i32 [[Y]]
132 ; CHECK-NEXT: ret i32 [[Y_FR]]
134 switch i8 %cond, label %A [
145 %y = phi i32 [undef, %A], [%x, %B], [0, %C]
146 %y.fr = freeze i32 %y
150 define i32 @one_undef(i8 %cond) {
151 ; CHECK-LABEL: @one_undef(
152 ; CHECK-NEXT: switch i8 [[COND:%.*]], label [[A:%.*]] [
153 ; CHECK-NEXT: i8 0, label [[B:%.*]]
154 ; CHECK-NEXT: i8 1, label [[C:%.*]]
157 ; CHECK-NEXT: br label [[D:%.*]]
159 ; CHECK-NEXT: br label [[D]]
161 ; CHECK-NEXT: br label [[D]]
163 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 0, [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
164 ; CHECK-NEXT: ret i32 [[Y]]
166 switch i8 %cond, label %A [
177 %y = phi i32 [undef, %A], [32, %B], [0, %C]
178 %y.fr = freeze i32 %y
184 define i32 @one_constexpr(i8 %cond, i32 %x) {
185 ; CHECK-LABEL: @one_constexpr(
186 ; CHECK-NEXT: switch i8 [[COND:%.*]], label [[A:%.*]] [
187 ; CHECK-NEXT: i8 0, label [[B:%.*]]
188 ; CHECK-NEXT: i8 1, label [[C:%.*]]
191 ; CHECK-NEXT: [[PHI_FR:%.*]] = freeze i32 ptrtoint (i8* getelementptr inbounds (i8, i8* @glb, i64 2) to i32)
192 ; CHECK-NEXT: br label [[D:%.*]]
194 ; CHECK-NEXT: br label [[D]]
196 ; CHECK-NEXT: br label [[D]]
198 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ [[PHI_FR]], [[A]] ], [ 32, [[B]] ], [ 0, [[C]] ]
199 ; CHECK-NEXT: ret i32 [[Y]]
201 switch i8 %cond, label %A [
212 %y = phi i32 [ptrtoint (i8* getelementptr inbounds (i8, i8* @glb, i64 2) to i32), %A], [32, %B], [0, %C]
213 %y.fr = freeze i32 %y