1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define i32 @select_or_icmp(i32 %x, i32 %y, i32 %z) {
5 ; CHECK-LABEL: @select_or_icmp(
6 ; CHECK-NEXT: ret i32 [[Z:%.*]]
8 %A = icmp ne i32 %x, %z
9 %B = icmp ne i32 %y, %z
11 %D = select i1 %C, i32 %z, i32 %x
15 define <2 x i8> @select_or_icmp_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
16 ; CHECK-LABEL: @select_or_icmp_vec(
17 ; CHECK-NEXT: ret <2 x i8> [[Z:%.*]]
19 %A = icmp ne <2 x i8> %x, %z
20 %B = icmp ne <2 x i8> %y, %z
21 %C = or <2 x i1> %A, %B
22 %D = select <2 x i1> %C, <2 x i8> %z, <2 x i8> %x
26 define i32 @select_or_icmp2(i32 %x, i32 %y, i32 %z) {
27 ; CHECK-LABEL: @select_or_icmp2(
28 ; CHECK-NEXT: ret i32 [[Z:%.*]]
30 %A = icmp ne i32 %x, %z
31 %B = icmp ne i32 %y, %z
33 %D = select i1 %C, i32 %z, i32 %y
37 define i32 @select_or_icmp_alt(i32 %x, i32 %y, i32 %z) {
38 ; CHECK-LABEL: @select_or_icmp_alt(
39 ; CHECK-NEXT: ret i32 [[X:%.*]]
41 %A = icmp ne i32 %x, %z
42 %B = icmp ne i32 %y, %z
44 %D = select i1 %C, i32 %x, i32 %z
48 define i32 @select_or_icmp_alt2(i32 %x, i32 %y, i32 %z) {
49 ; CHECK-LABEL: @select_or_icmp_alt2(
50 ; CHECK-NEXT: ret i32 [[Y:%.*]]
52 %A = icmp ne i32 %x, %z
53 %B = icmp ne i32 %y, %z
55 %D = select i1 %C, i32 %y, i32 %z
59 define i32 @select_or_icmp_inv_alt(i32 %x, i32 %y, i32 %z) {
60 ; CHECK-LABEL: @select_or_icmp_inv_alt(
61 ; CHECK-NEXT: ret i32 [[X:%.*]]
63 %A = icmp ne i32 %z, %x
64 %B = icmp ne i32 %z, %y
66 %D = select i1 %C, i32 %x, i32 %z
70 define i32 @select_or_inv_icmp_alt(i32 %x, i32 %y, i32 %z) {
71 ; CHECK-LABEL: @select_or_inv_icmp_alt(
72 ; CHECK-NEXT: ret i32 [[X:%.*]]
74 %A = icmp ne i32 %z, %x
75 %B = icmp ne i32 %z, %y
77 %D = select i1 %C, i32 %x, i32 %z
81 define <2 x i8> @select_or_icmp_alt_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
82 ; CHECK-LABEL: @select_or_icmp_alt_vec(
83 ; CHECK-NEXT: ret <2 x i8> [[X:%.*]]
85 %A = icmp ne <2 x i8> %x, %z
86 %B = icmp ne <2 x i8> %y, %z
87 %C = or <2 x i1> %A, %B
88 %D = select <2 x i1> %C, <2 x i8> %x, <2 x i8> %z
92 define i32 @select_or_inv_icmp(i32 %x, i32 %y, i32 %z) {
93 ; CHECK-LABEL: @select_or_inv_icmp(
94 ; CHECK-NEXT: ret i32 [[Z:%.*]]
96 %A = icmp ne i32 %x, %z
97 %B = icmp ne i32 %y, %z
99 %D = select i1 %C, i32 %z, i32 %x
103 define i32 @select_or_icmp_inv(i32 %x, i32 %y, i32 %z) {
104 ; CHECK-LABEL: @select_or_icmp_inv(
105 ; CHECK-NEXT: ret i32 [[Z:%.*]]
107 %A = icmp ne i32 %z, %x
108 %B = icmp ne i32 %z, %y
110 %D = select i1 %C, i32 %z, i32 %x
115 define i32 @select_and_icmp_pred_bad_1(i32 %x, i32 %y, i32 %z) {
116 ; CHECK-LABEL: @select_and_icmp_pred_bad_1(
117 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
118 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
119 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
120 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
121 ; CHECK-NEXT: ret i32 [[D]]
123 %A = icmp eq i32 %x, %z
124 %B = icmp ne i32 %y, %z
126 %D = select i1 %C, i32 %z, i32 %x
130 define i32 @select_and_icmp_pred_bad_2(i32 %x, i32 %y, i32 %z) {
131 ; CHECK-LABEL: @select_and_icmp_pred_bad_2(
132 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
133 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
134 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
135 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
136 ; CHECK-NEXT: ret i32 [[D]]
138 %A = icmp ne i32 %x, %z
139 %B = icmp eq i32 %y, %z
141 %D = select i1 %C, i32 %z, i32 %x
145 define i32 @select_and_icmp_pred_bad_3(i32 %x, i32 %y, i32 %z) {
146 ; CHECK-LABEL: @select_and_icmp_pred_bad_3(
147 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
148 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
149 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
150 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
151 ; CHECK-NEXT: ret i32 [[D]]
153 %A = icmp eq i32 %x, %z
154 %B = icmp eq i32 %y, %z
156 %D = select i1 %C, i32 %z, i32 %x
160 define i32 @select_and_icmp_pred_bad_4(i32 %x, i32 %y, i32 %z) {
161 ; CHECK-LABEL: @select_and_icmp_pred_bad_4(
162 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
163 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
164 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
165 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
166 ; CHECK-NEXT: ret i32 [[D]]
168 %A = icmp ne i32 %x, %z
169 %B = icmp ne i32 %y, %z
171 %D = select i1 %C, i32 %z, i32 %x
175 define i32 @select_or_icmp_bad_true_val(i32 %x, i32 %y, i32 %z, i32 %k) {
176 ; CHECK-LABEL: @select_or_icmp_bad_true_val(
177 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
178 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
179 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
180 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[K:%.*]], i32 [[X]]
181 ; CHECK-NEXT: ret i32 [[D]]
183 %A = icmp ne i32 %x, %z
184 %B = icmp ne i32 %y, %z
186 %D = select i1 %C, i32 %k, i32 %x
190 define i32 @select_or_icmp_bad_false_val(i32 %x, i32 %y, i32 %z, i32 %k) {
191 ; CHECK-LABEL: @select_or_icmp_bad_false_val(
192 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
193 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
194 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
195 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[K:%.*]]
196 ; CHECK-NEXT: ret i32 [[D]]
198 %A = icmp ne i32 %x, %z
199 %B = icmp ne i32 %y, %z
201 %D = select i1 %C, i32 %z, i32 %k
205 define i32 @select_or_icmp_bad_op(i32 %x, i32 %y, i32 %z, i32 %k) {
206 ; CHECK-LABEL: @select_or_icmp_bad_op(
207 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[K:%.*]], [[Z:%.*]]
208 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
209 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
210 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X:%.*]]
211 ; CHECK-NEXT: ret i32 [[D]]
213 %A = icmp ne i32 %k, %z
214 %B = icmp ne i32 %y, %z
216 %D = select i1 %C, i32 %z, i32 %x
221 define i32 @select_or_icmp_bad_op_2(i32 %x, i32 %y, i32 %z, i32 %k) {
222 ; CHECK-LABEL: @select_or_icmp_bad_op_2(
223 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[K:%.*]]
224 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z:%.*]]
225 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
226 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[Z]], i32 [[X]]
227 ; CHECK-NEXT: ret i32 [[D]]
229 %A = icmp ne i32 %x, %k
230 %B = icmp ne i32 %y, %z
232 %D = select i1 %C, i32 %z, i32 %x
236 define i32 @select_or_icmp_alt_bad_1(i32 %x, i32 %y, i32 %z) {
237 ; CHECK-LABEL: @select_or_icmp_alt_bad_1(
238 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
239 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
240 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
241 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
242 ; CHECK-NEXT: ret i32 [[D]]
244 %A = icmp eq i32 %x, %z
245 %B = icmp ne i32 %y, %z
247 %D = select i1 %C, i32 %x, i32 %z
251 define i32 @select_or_icmp_alt_bad_2(i32 %x, i32 %y, i32 %z) {
252 ; CHECK-LABEL: @select_or_icmp_alt_bad_2(
253 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
254 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
255 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
256 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
257 ; CHECK-NEXT: ret i32 [[D]]
259 %A = icmp ne i32 %x, %z
260 %B = icmp eq i32 %y, %z
262 %D = select i1 %C, i32 %x, i32 %z
266 define i32 @select_or_icmp_alt_bad_3(i32 %x, i32 %y, i32 %z) {
267 ; CHECK-LABEL: @select_or_icmp_alt_bad_3(
268 ; CHECK-NEXT: [[A:%.*]] = icmp eq i32 [[X:%.*]], [[Z:%.*]]
269 ; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[Y:%.*]], [[Z]]
270 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
271 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
272 ; CHECK-NEXT: ret i32 [[D]]
274 %A = icmp eq i32 %x, %z
275 %B = icmp eq i32 %y, %z
277 %D = select i1 %C, i32 %x, i32 %z
281 define i32 @select_or_icmp_alt_bad_4(i32 %x, i32 %y, i32 %z) {
282 ; CHECK-LABEL: @select_or_icmp_alt_bad_4(
283 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
284 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
285 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A]], [[B]]
286 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
287 ; CHECK-NEXT: ret i32 [[D]]
289 %A = icmp ne i32 %x, %z
290 %B = icmp ne i32 %y, %z
292 %D = select i1 %C, i32 %x, i32 %z
296 define i32 @select_or_icmp_alt_bad_5(i32 %x, i32 %y, i32 %z, i32 %k) {
297 ; CHECK-LABEL: @select_or_icmp_alt_bad_5(
298 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[K:%.*]]
299 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z:%.*]]
300 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
301 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[Z]]
302 ; CHECK-NEXT: ret i32 [[D]]
304 %A = icmp ne i32 %x, %k
305 %B = icmp ne i32 %y, %z
307 %D = select i1 %C, i32 %x, i32 %z
311 define i32 @select_or_icmp_alt_bad_true_val(i32 %x, i32 %y, i32 %z, i32 %k) {
312 ; CHECK-LABEL: @select_or_icmp_alt_bad_true_val(
313 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
314 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
315 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
316 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[K:%.*]], i32 [[Z]]
317 ; CHECK-NEXT: ret i32 [[D]]
319 %A = icmp ne i32 %x, %z
320 %B = icmp ne i32 %y, %z
322 %D = select i1 %C, i32 %k, i32 %z
326 define i32 @select_or_icmp_alt_bad_false_val(i32 %x, i32 %y, i32 %z, i32 %k) {
327 ; CHECK-LABEL: @select_or_icmp_alt_bad_false_val(
328 ; CHECK-NEXT: [[A:%.*]] = icmp ne i32 [[X:%.*]], [[Z:%.*]]
329 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[Y:%.*]], [[Z]]
330 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A]], [[B]]
331 ; CHECK-NEXT: [[D:%.*]] = select i1 [[C]], i32 [[X]], i32 [[K:%.*]]
332 ; CHECK-NEXT: ret i32 [[D]]
334 %A = icmp ne i32 %x, %z
335 %B = icmp ne i32 %y, %z
337 %D = select i1 %C, i32 %x, i32 %k