1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "n8:16:32:64"
6 define i32 @select_icmp_eq_and_1_0_or_2(i32 %x, i32 %y) {
7 ; CHECK-LABEL: @select_icmp_eq_and_1_0_or_2(
8 ; CHECK-NEXT: [[AND:%.*]] = shl i32 [[X:%.*]], 1
9 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[AND]], 2
10 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
11 ; CHECK-NEXT: ret i32 [[TMP2]]
14 %cmp = icmp eq i32 %and, 0
16 %select = select i1 %cmp, i32 %y, i32 %or
20 define <2 x i32> @select_icmp_eq_and_1_0_or_2_vec(<2 x i32> %x, <2 x i32> %y) {
21 ; CHECK-LABEL: @select_icmp_eq_and_1_0_or_2_vec(
22 ; CHECK-NEXT: [[AND:%.*]] = shl <2 x i32> [[X:%.*]], <i32 1, i32 1>
23 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[AND]], <i32 2, i32 2>
24 ; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i32> [[TMP1]], [[Y:%.*]]
25 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
27 %and = and <2 x i32> %x, <i32 1, i32 1>
28 %cmp = icmp eq <2 x i32> %and, zeroinitializer
29 %or = or <2 x i32> %y, <i32 2, i32 2>
30 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
34 define i32 @select_icmp_eq_and_1_0_xor_2(i32 %x, i32 %y) {
35 ; CHECK-LABEL: @select_icmp_eq_and_1_0_xor_2(
36 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
37 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
38 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2
39 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
40 ; CHECK-NEXT: ret i32 [[SELECT]]
43 %cmp = icmp eq i32 %and, 0
45 %select = select i1 %cmp, i32 %y, i32 %xor
49 define i32 @select_icmp_eq_and_1_0_and_not_2(i32 %x, i32 %y) {
50 ; CHECK-LABEL: @select_icmp_eq_and_1_0_and_not_2(
51 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
52 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
53 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -3
54 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
55 ; CHECK-NEXT: ret i32 [[SELECT]]
58 %cmp = icmp eq i32 %and, 0
59 %and2 = and i32 %y, -3
60 %select = select i1 %cmp, i32 %y, i32 %and2
64 define i32 @select_icmp_eq_and_32_0_or_8(i32 %x, i32 %y) {
65 ; CHECK-LABEL: @select_icmp_eq_and_32_0_or_8(
66 ; CHECK-NEXT: [[AND:%.*]] = lshr i32 [[X:%.*]], 2
67 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[AND]], 8
68 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
69 ; CHECK-NEXT: ret i32 [[TMP2]]
72 %cmp = icmp eq i32 %and, 0
74 %select = select i1 %cmp, i32 %y, i32 %or
78 define <2 x i32> @select_icmp_eq_and_32_0_or_8_vec(<2 x i32> %x, <2 x i32> %y) {
79 ; CHECK-LABEL: @select_icmp_eq_and_32_0_or_8_vec(
80 ; CHECK-NEXT: [[AND:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 2, i32 2>
81 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[AND]], <i32 8, i32 8>
82 ; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i32> [[TMP1]], [[Y:%.*]]
83 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
85 %and = and <2 x i32> %x, <i32 32, i32 32>
86 %cmp = icmp eq <2 x i32> %and, zeroinitializer
87 %or = or <2 x i32> %y, <i32 8, i32 8>
88 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
92 define i32 @select_icmp_eq_and_32_0_xor_8(i32 %x, i32 %y) {
93 ; CHECK-LABEL: @select_icmp_eq_and_32_0_xor_8(
94 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 32
95 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
96 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 8
97 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
98 ; CHECK-NEXT: ret i32 [[SELECT]]
100 %and = and i32 %x, 32
101 %cmp = icmp eq i32 %and, 0
103 %select = select i1 %cmp, i32 %y, i32 %xor
107 define i32 @select_icmp_eq_and_32_0_and_not_8(i32 %x, i32 %y) {
108 ; CHECK-LABEL: @select_icmp_eq_and_32_0_and_not_8(
109 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 32
110 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
111 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -9
112 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
113 ; CHECK-NEXT: ret i32 [[SELECT]]
115 %and = and i32 %x, 32
116 %cmp = icmp eq i32 %and, 0
117 %and2 = and i32 %y, -9
118 %select = select i1 %cmp, i32 %y, i32 %and2
122 define i32 @select_icmp_ne_0_and_4096_or_4096(i32 %x, i32 %y) {
123 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_or_4096(
124 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
125 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[AND]], 4096
126 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
127 ; CHECK-NEXT: ret i32 [[TMP2]]
129 %and = and i32 %x, 4096
130 %cmp = icmp ne i32 0, %and
131 %or = or i32 %y, 4096
132 %select = select i1 %cmp, i32 %y, i32 %or
136 define <2 x i32> @select_icmp_ne_0_and_4096_or_4096_vec(<2 x i32> %x, <2 x i32> %y) {
137 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_or_4096_vec(
138 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 4096, i32 4096>
139 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[AND]], <i32 4096, i32 4096>
140 ; CHECK-NEXT: [[TMP2:%.*]] = or <2 x i32> [[TMP1]], [[Y:%.*]]
141 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
143 %and = and <2 x i32> %x, <i32 4096, i32 4096>
144 %cmp = icmp ne <2 x i32> zeroinitializer, %and
145 %or = or <2 x i32> %y, <i32 4096, i32 4096>
146 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
147 ret <2 x i32> %select
150 define i32 @select_icmp_ne_0_and_4096_xor_4096(i32 %x, i32 %y) {
151 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_xor_4096(
152 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
153 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
154 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
155 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 [[Y]]
156 ; CHECK-NEXT: ret i32 [[SELECT]]
158 %and = and i32 %x, 4096
159 %cmp = icmp ne i32 0, %and
160 %xor = xor i32 %y, 4096
161 %select = select i1 %cmp, i32 %y, i32 %xor
165 define i32 @select_icmp_ne_0_and_4096_and_not_4096(i32 %x, i32 %y) {
166 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_and_not_4096(
167 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
168 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
169 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
170 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[AND2]], i32 [[Y]]
171 ; CHECK-NEXT: ret i32 [[SELECT]]
173 %and = and i32 %x, 4096
174 %cmp = icmp ne i32 0, %and
175 %and2 = and i32 %y, -4097
176 %select = select i1 %cmp, i32 %y, i32 %and2
180 define i32 @select_icmp_eq_and_4096_0_or_4096(i32 %x, i32 %y) {
181 ; CHECK-LABEL: @select_icmp_eq_and_4096_0_or_4096(
182 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
183 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[AND]], [[Y:%.*]]
184 ; CHECK-NEXT: ret i32 [[TMP1]]
186 %and = and i32 %x, 4096
187 %cmp = icmp eq i32 %and, 0
188 %or = or i32 %y, 4096
189 %select = select i1 %cmp, i32 %y, i32 %or
193 define <2 x i32> @select_icmp_eq_and_4096_0_or_4096_vec(<2 x i32> %x, <2 x i32> %y) {
194 ; CHECK-LABEL: @select_icmp_eq_and_4096_0_or_4096_vec(
195 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 4096, i32 4096>
196 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[AND]], [[Y:%.*]]
197 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
199 %and = and <2 x i32> %x, <i32 4096, i32 4096>
200 %cmp = icmp eq <2 x i32> %and, zeroinitializer
201 %or = or <2 x i32> %y, <i32 4096, i32 4096>
202 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
203 ret <2 x i32> %select
206 define i32 @select_icmp_eq_and_4096_0_xor_4096(i32 %x, i32 %y) {
207 ; CHECK-LABEL: @select_icmp_eq_and_4096_0_xor_4096(
208 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
209 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
210 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
211 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
212 ; CHECK-NEXT: ret i32 [[SELECT]]
214 %and = and i32 %x, 4096
215 %cmp = icmp eq i32 %and, 0
216 %xor = xor i32 %y, 4096
217 %select = select i1 %cmp, i32 %y, i32 %xor
221 define i32 @select_icmp_eq_and_4096_0_and_not_4096(i32 %x, i32 %y) {
222 ; CHECK-LABEL: @select_icmp_eq_and_4096_0_and_not_4096(
223 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
224 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
225 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
226 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
227 ; CHECK-NEXT: ret i32 [[SELECT]]
229 %and = and i32 %x, 4096
230 %cmp = icmp eq i32 %and, 0
231 %and2 = and i32 %y, -4097
232 %select = select i1 %cmp, i32 %y, i32 %and2
236 define i32 @select_icmp_eq_0_and_1_or_1(i64 %x, i32 %y) {
237 ; CHECK-LABEL: @select_icmp_eq_0_and_1_or_1(
238 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[X:%.*]] to i32
239 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1
240 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP2]], [[Y:%.*]]
241 ; CHECK-NEXT: ret i32 [[TMP3]]
244 %cmp = icmp eq i64 %and, 0
246 %select = select i1 %cmp, i32 %y, i32 %or
250 define <2 x i32> @select_icmp_eq_0_and_1_or_1_vec(<2 x i64> %x, <2 x i32> %y) {
251 ; CHECK-LABEL: @select_icmp_eq_0_and_1_or_1_vec(
252 ; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i64> [[X:%.*]] to <2 x i32>
253 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 1, i32 1>
254 ; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> [[TMP2]], [[Y:%.*]]
255 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
257 %and = and <2 x i64> %x, <i64 1, i64 1>
258 %cmp = icmp eq <2 x i64> %and, zeroinitializer
259 %or = or <2 x i32> %y, <i32 1, i32 1>
260 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
261 ret <2 x i32> %select
264 define i32 @select_icmp_eq_0_and_1_xor_1(i64 %x, i32 %y) {
265 ; CHECK-LABEL: @select_icmp_eq_0_and_1_xor_1(
266 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[X:%.*]] to i32
267 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 1
268 ; CHECK-NEXT: [[SELECT:%.*]] = xor i32 [[TMP2]], [[Y:%.*]]
269 ; CHECK-NEXT: ret i32 [[SELECT]]
272 %cmp = icmp eq i64 %and, 0
274 %select = select i1 %cmp, i32 %y, i32 %xor
278 define i32 @select_icmp_eq_0_and_1_and_not_1(i64 %x, i32 %y) {
279 ; CHECK-LABEL: @select_icmp_eq_0_and_1_and_not_1(
280 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[X:%.*]], 1
281 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[AND]], 0
282 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -2
283 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
284 ; CHECK-NEXT: ret i32 [[SELECT]]
287 %cmp = icmp eq i64 %and, 0
288 %and2 = and i32 %y, -2
289 %select = select i1 %cmp, i32 %y, i32 %and2
293 define i32 @select_icmp_ne_0_and_4096_or_32(i32 %x, i32 %y) {
294 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_or_32(
295 ; CHECK-NEXT: [[AND:%.*]] = lshr i32 [[X:%.*]], 7
296 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[AND]], 32
297 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 32
298 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP2]], [[Y:%.*]]
299 ; CHECK-NEXT: ret i32 [[TMP3]]
301 %and = and i32 %x, 4096
302 %cmp = icmp ne i32 0, %and
304 %select = select i1 %cmp, i32 %y, i32 %or
308 define i32 @select_icmp_ne_0_and_4096_xor_32(i32 %x, i32 %y) {
309 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_xor_32(
310 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
311 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
312 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 32
313 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 [[Y]]
314 ; CHECK-NEXT: ret i32 [[SELECT]]
316 %and = and i32 %x, 4096
317 %cmp = icmp ne i32 0, %and
318 %xor = xor i32 %y, 32
319 %select = select i1 %cmp, i32 %y, i32 %xor
323 define i32 @select_icmp_ne_0_and_4096_and_not_32(i32 %x, i32 %y) {
324 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_and_not_32(
325 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
326 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
327 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -33
328 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[AND2]], i32 [[Y]]
329 ; CHECK-NEXT: ret i32 [[SELECT]]
331 %and = and i32 %x, 4096
332 %cmp = icmp ne i32 0, %and
333 %and2 = and i32 %y, -33
334 %select = select i1 %cmp, i32 %y, i32 %and2
338 define i32 @select_icmp_ne_0_and_32_or_4096(i32 %x, i32 %y) {
339 ; CHECK-LABEL: @select_icmp_ne_0_and_32_or_4096(
340 ; CHECK-NEXT: [[AND:%.*]] = shl i32 [[X:%.*]], 7
341 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[AND]], 4096
342 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 4096
343 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP2]], [[Y:%.*]]
344 ; CHECK-NEXT: ret i32 [[TMP3]]
346 %and = and i32 %x, 32
347 %cmp = icmp ne i32 0, %and
348 %or = or i32 %y, 4096
349 %select = select i1 %cmp, i32 %y, i32 %or
353 define <2 x i32> @select_icmp_ne_0_and_32_or_4096_vec(<2 x i32> %x, <2 x i32> %y) {
354 ; CHECK-LABEL: @select_icmp_ne_0_and_32_or_4096_vec(
355 ; CHECK-NEXT: [[AND:%.*]] = shl <2 x i32> [[X:%.*]], <i32 7, i32 7>
356 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[AND]], <i32 4096, i32 4096>
357 ; CHECK-NEXT: [[TMP2:%.*]] = xor <2 x i32> [[TMP1]], <i32 4096, i32 4096>
358 ; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> [[TMP2]], [[Y:%.*]]
359 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
361 %and = and <2 x i32> %x, <i32 32, i32 32>
362 %cmp = icmp ne <2 x i32> zeroinitializer, %and
363 %or = or <2 x i32> %y, <i32 4096, i32 4096>
364 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
365 ret <2 x i32> %select
368 define i32 @select_icmp_ne_0_and_32_xor_4096(i32 %x, i32 %y) {
369 ; CHECK-LABEL: @select_icmp_ne_0_and_32_xor_4096(
370 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 32
371 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
372 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
373 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 [[Y]]
374 ; CHECK-NEXT: ret i32 [[SELECT]]
376 %and = and i32 %x, 32
377 %cmp = icmp ne i32 0, %and
378 %xor = xor i32 %y, 4096
379 %select = select i1 %cmp, i32 %y, i32 %xor
383 define i32 @select_icmp_ne_0_and_32_and_not_4096(i32 %x, i32 %y) {
384 ; CHECK-LABEL: @select_icmp_ne_0_and_32_and_not_4096(
385 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 32
386 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
387 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
388 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[AND2]], i32 [[Y]]
389 ; CHECK-NEXT: ret i32 [[SELECT]]
391 %and = and i32 %x, 32
392 %cmp = icmp ne i32 0, %and
393 %and2 = and i32 %y, -4097
394 %select = select i1 %cmp, i32 %y, i32 %and2
398 define i8 @select_icmp_ne_0_and_1073741824_or_8(i32 %x, i8 %y) {
399 ; CHECK-LABEL: @select_icmp_ne_0_and_1073741824_or_8(
400 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1073741824
401 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
402 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 8
403 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i8 [[OR]], i8 [[Y]]
404 ; CHECK-NEXT: ret i8 [[SELECT]]
406 %and = and i32 %x, 1073741824
407 %cmp = icmp ne i32 0, %and
409 %select = select i1 %cmp, i8 %y, i8 %or
413 define i8 @select_icmp_ne_0_and_1073741824_xor_8(i32 %x, i8 %y) {
414 ; CHECK-LABEL: @select_icmp_ne_0_and_1073741824_xor_8(
415 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1073741824
416 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
417 ; CHECK-NEXT: [[XOR:%.*]] = xor i8 [[Y:%.*]], 8
418 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i8 [[XOR]], i8 [[Y]]
419 ; CHECK-NEXT: ret i8 [[SELECT]]
421 %and = and i32 %x, 1073741824
422 %cmp = icmp ne i32 0, %and
424 %select = select i1 %cmp, i8 %y, i8 %xor
428 define i8 @select_icmp_ne_0_and_1073741824_and_not_8(i32 %x, i8 %y) {
429 ; CHECK-LABEL: @select_icmp_ne_0_and_1073741824_and_not_8(
430 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1073741824
431 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
432 ; CHECK-NEXT: [[AND2:%.*]] = and i8 [[Y:%.*]], -9
433 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i8 [[AND2]], i8 [[Y]]
434 ; CHECK-NEXT: ret i8 [[SELECT]]
436 %and = and i32 %x, 1073741824
437 %cmp = icmp ne i32 0, %and
438 %and2 = and i8 %y, -9
439 %select = select i1 %cmp, i8 %y, i8 %and2
443 define i32 @select_icmp_ne_0_and_8_or_1073741824(i8 %x, i32 %y) {
444 ; CHECK-LABEL: @select_icmp_ne_0_and_8_or_1073741824(
445 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 8
446 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0
447 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 1073741824
448 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[OR]], i32 [[Y]]
449 ; CHECK-NEXT: ret i32 [[SELECT]]
452 %cmp = icmp ne i8 0, %and
453 %or = or i32 %y, 1073741824
454 %select = select i1 %cmp, i32 %y, i32 %or
458 define i32 @select_icmp_ne_0_and_8_xor_1073741824(i8 %x, i32 %y) {
459 ; CHECK-LABEL: @select_icmp_ne_0_and_8_xor_1073741824(
460 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 8
461 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0
462 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 1073741824
463 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 [[Y]]
464 ; CHECK-NEXT: ret i32 [[SELECT]]
467 %cmp = icmp ne i8 0, %and
468 %xor = xor i32 %y, 1073741824
469 %select = select i1 %cmp, i32 %y, i32 %xor
473 define i32 @select_icmp_ne_0_and_8_and_not_1073741824(i8 %x, i32 %y) {
474 ; CHECK-LABEL: @select_icmp_ne_0_and_8_and_not_1073741824(
475 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[X:%.*]], 8
476 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0
477 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -1073741825
478 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[AND2]], i32 [[Y]]
479 ; CHECK-NEXT: ret i32 [[SELECT]]
482 %cmp = icmp ne i8 0, %and
483 %and2 = and i32 %y, -1073741825
484 %select = select i1 %cmp, i32 %y, i32 %and2
488 ; We can't combine here, because the cmp is scalar and the or vector.
489 ; Just make sure we don't assert.
490 define <2 x i32> @select_icmp_eq_and_1_0_or_vector_of_2s(i32 %x, <2 x i32> %y) {
491 ; CHECK-LABEL: @select_icmp_eq_and_1_0_or_vector_of_2s(
492 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
493 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
494 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[Y:%.*]], <i32 2, i32 2>
495 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x i32> [[Y]], <2 x i32> [[OR]]
496 ; CHECK-NEXT: ret <2 x i32> [[SELECT]]
499 %cmp = icmp eq i32 %and, 0
500 %or = or <2 x i32> %y, <i32 2, i32 2>
501 %select = select i1 %cmp, <2 x i32> %y, <2 x i32> %or
502 ret <2 x i32> %select
505 define i32 @select_icmp_and_8_ne_0_xor_8(i32 %x) {
506 ; CHECK-LABEL: @select_icmp_and_8_ne_0_xor_8(
507 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], -9
508 ; CHECK-NEXT: ret i32 [[TMP1]]
511 %cmp = icmp eq i32 %and, 0
513 %x.xor = select i1 %cmp, i32 %x, i32 %xor
517 define i32 @select_icmp_and_8_eq_0_xor_8(i32 %x) {
518 ; CHECK-LABEL: @select_icmp_and_8_eq_0_xor_8(
519 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], 8
520 ; CHECK-NEXT: ret i32 [[TMP1]]
523 %cmp = icmp eq i32 %and, 0
525 %xor.x = select i1 %cmp, i32 %xor, i32 %x
529 define i64 @select_icmp_x_and_8_eq_0_y_xor_8(i32 %x, i64 %y) {
530 ; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_xor_8(
531 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 8
532 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
533 ; CHECK-NEXT: [[XOR:%.*]] = xor i64 [[Y:%.*]], 8
534 ; CHECK-NEXT: [[Y_XOR:%.*]] = select i1 [[CMP]], i64 [[Y]], i64 [[XOR]]
535 ; CHECK-NEXT: ret i64 [[Y_XOR]]
538 %cmp = icmp eq i32 %and, 0
540 %y.xor = select i1 %cmp, i64 %y, i64 %xor
544 define i64 @select_icmp_x_and_8_ne_0_y_xor_8(i32 %x, i64 %y) {
545 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_xor_8(
546 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 8
547 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
548 ; CHECK-NEXT: [[XOR:%.*]] = xor i64 [[Y:%.*]], 8
549 ; CHECK-NEXT: [[XOR_Y:%.*]] = select i1 [[CMP]], i64 [[XOR]], i64 [[Y]]
550 ; CHECK-NEXT: ret i64 [[XOR_Y]]
553 %cmp = icmp eq i32 %and, 0
555 %xor.y = select i1 %cmp, i64 %xor, i64 %y
559 define i64 @select_icmp_x_and_8_ne_0_y_or_8(i32 %x, i64 %y) {
560 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_or_8(
561 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 8
562 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[AND]], 8
563 ; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64
564 ; CHECK-NEXT: [[TMP3:%.*]] = or i64 [[TMP2]], [[Y:%.*]]
565 ; CHECK-NEXT: ret i64 [[TMP3]]
568 %cmp = icmp eq i32 %and, 0
570 %or.y = select i1 %cmp, i64 %or, i64 %y
574 define <2 x i64> @select_icmp_x_and_8_ne_0_y_or_8_vec(<2 x i32> %x, <2 x i64> %y) {
575 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_or_8_vec(
576 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 8, i32 8>
577 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[AND]], <i32 8, i32 8>
578 ; CHECK-NEXT: [[TMP2:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
579 ; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i64> [[TMP2]], [[Y:%.*]]
580 ; CHECK-NEXT: ret <2 x i64> [[TMP3]]
582 %and = and <2 x i32> %x, <i32 8, i32 8>
583 %cmp = icmp eq <2 x i32> %and, zeroinitializer
584 %or = or <2 x i64> %y, <i64 8, i64 8>
585 %or.y = select <2 x i1> %cmp, <2 x i64> %or, <2 x i64> %y
589 define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) {
590 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8(
591 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 8
592 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
593 ; CHECK-NEXT: [[AND2:%.*]] = and i64 [[Y:%.*]], -9
594 ; CHECK-NEXT: [[AND_Y:%.*]] = select i1 [[CMP]], i64 [[AND2]], i64 [[Y]]
595 ; CHECK-NEXT: ret i64 [[AND_Y]]
598 %cmp = icmp eq i32 %and, 0
599 %and2 = and i64 %y, -9
600 %and.y = select i1 %cmp, i64 %and2, i64 %y
604 define i32 @select_icmp_and_2147483648_ne_0_xor_2147483648(i32 %x) {
605 ; CHECK-LABEL: @select_icmp_and_2147483648_ne_0_xor_2147483648(
606 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 2147483647
607 ; CHECK-NEXT: ret i32 [[TMP1]]
609 %and = and i32 %x, 2147483648
610 %cmp = icmp eq i32 %and, 0
611 %xor = xor i32 %x, 2147483648
612 %x.xor = select i1 %cmp, i32 %x, i32 %xor
616 define i32 @select_icmp_and_2147483648_eq_0_xor_2147483648(i32 %x) {
617 ; CHECK-LABEL: @select_icmp_and_2147483648_eq_0_xor_2147483648(
618 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -2147483648
619 ; CHECK-NEXT: ret i32 [[TMP1]]
621 %and = and i32 %x, 2147483648
622 %cmp = icmp eq i32 %and, 0
623 %xor = xor i32 %x, 2147483648
624 %xor.x = select i1 %cmp, i32 %xor, i32 %x
628 define i32 @select_icmp_x_and_2147483648_ne_0_or_2147483648(i32 %x) {
629 ; CHECK-LABEL: @select_icmp_x_and_2147483648_ne_0_or_2147483648(
630 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], -2147483648
631 ; CHECK-NEXT: ret i32 [[OR]]
633 %and = and i32 %x, 2147483648
634 %cmp = icmp eq i32 %and, 0
635 %or = or i32 %x, 2147483648
636 %or.x = select i1 %cmp, i32 %or, i32 %x
640 define i32 @test68(i32 %x, i32 %y) {
641 ; CHECK-LABEL: @test68(
642 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 6
643 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 2
644 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP2]], [[Y:%.*]]
645 ; CHECK-NEXT: ret i32 [[TMP3]]
647 %and = and i32 %x, 128
648 %cmp = icmp eq i32 %and, 0
650 %select = select i1 %cmp, i32 %y, i32 %or
654 define <2 x i32> @test68vec(<2 x i32> %x, <2 x i32> %y) {
655 ; CHECK-LABEL: @test68vec(
656 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 6, i32 6>
657 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 2, i32 2>
658 ; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> [[TMP2]], [[Y:%.*]]
659 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
661 %and = and <2 x i32> %x, <i32 128, i32 128>
662 %cmp = icmp eq <2 x i32> %and, zeroinitializer
663 %or = or <2 x i32> %y, <i32 2, i32 2>
664 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
665 ret <2 x i32> %select
668 define i32 @test68_xor(i32 %x, i32 %y) {
669 ; CHECK-LABEL: @test68_xor(
670 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
671 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[TMP1]], -1
672 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2
673 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
674 ; CHECK-NEXT: ret i32 [[SELECT]]
676 %and = and i32 %x, 128
677 %cmp = icmp eq i32 %and, 0
679 %select = select i1 %cmp, i32 %y, i32 %xor
683 define i32 @test68_and(i32 %x, i32 %y) {
684 ; CHECK-LABEL: @test68_and(
685 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
686 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[TMP1]], -1
687 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -3
688 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
689 ; CHECK-NEXT: ret i32 [[SELECT]]
691 %and = and i32 %x, 128
692 %cmp = icmp eq i32 %and, 0
693 %and2 = and i32 %y, -3
694 %select = select i1 %cmp, i32 %y, i32 %and2
698 define i32 @test69(i32 %x, i32 %y) {
699 ; CHECK-LABEL: @test69(
700 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 6
701 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 2
702 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP2]], 2
703 ; CHECK-NEXT: [[TMP4:%.*]] = or i32 [[TMP3]], [[Y:%.*]]
704 ; CHECK-NEXT: ret i32 [[TMP4]]
706 %and = and i32 %x, 128
707 %cmp = icmp ne i32 %and, 0
709 %select = select i1 %cmp, i32 %y, i32 %or
713 define <2 x i32> @test69vec(<2 x i32> %x, <2 x i32> %y) {
714 ; CHECK-LABEL: @test69vec(
715 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 6, i32 6>
716 ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 2, i32 2>
717 ; CHECK-NEXT: [[TMP3:%.*]] = xor <2 x i32> [[TMP2]], <i32 2, i32 2>
718 ; CHECK-NEXT: [[TMP4:%.*]] = or <2 x i32> [[TMP3]], [[Y:%.*]]
719 ; CHECK-NEXT: ret <2 x i32> [[TMP4]]
721 %and = and <2 x i32> %x, <i32 128, i32 128>
722 %cmp = icmp ne <2 x i32> %and, zeroinitializer
723 %or = or <2 x i32> %y, <i32 2, i32 2>
724 %select = select <2 x i1> %cmp, <2 x i32> %y, <2 x i32> %or
725 ret <2 x i32> %select
728 define i32 @test69_xor(i32 %x, i32 %y) {
729 ; CHECK-LABEL: @test69_xor(
730 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
731 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TMP1]], 0
732 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2
733 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
734 ; CHECK-NEXT: ret i32 [[SELECT]]
736 %and = and i32 %x, 128
737 %cmp = icmp ne i32 %and, 0
739 %select = select i1 %cmp, i32 %y, i32 %xor
743 define i32 @test69_and(i32 %x, i32 %y) {
744 ; CHECK-LABEL: @test69_and(
745 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
746 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[TMP1]], 0
747 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], 2
748 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
749 ; CHECK-NEXT: ret i32 [[SELECT]]
751 %and = and i32 %x, 128
752 %cmp = icmp ne i32 %and, 0
753 %and2 = and i32 %y, 2
754 %select = select i1 %cmp, i32 %y, i32 %and2
758 define i8 @test70(i8 %x, i8 %y) {
759 ; CHECK-LABEL: @test70(
760 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
761 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2
762 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i8 [[OR]], i8 [[Y]]
763 ; CHECK-NEXT: ret i8 [[SELECT]]
765 %cmp = icmp slt i8 %x, 0
767 %select = select i1 %cmp, i8 %or, i8 %y
771 define i32 @shift_no_xor_multiuse_or(i32 %x, i32 %y) {
772 ; CHECK-LABEL: @shift_no_xor_multiuse_or(
773 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 2
774 ; CHECK-NEXT: [[AND:%.*]] = shl i32 [[X:%.*]], 1
775 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[AND]], 2
776 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y]]
777 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP2]], [[OR]]
778 ; CHECK-NEXT: ret i32 [[RES]]
781 %cmp = icmp eq i32 %and, 0
783 %select = select i1 %cmp, i32 %y, i32 %or
784 %res = mul i32 %select, %or ; to bump up use count of the Or
788 define i32 @shift_no_xor_multiuse_xor(i32 %x, i32 %y) {
789 ; CHECK-LABEL: @shift_no_xor_multiuse_xor(
790 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
791 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
792 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2
793 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
794 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[XOR]]
795 ; CHECK-NEXT: ret i32 [[RES]]
798 %cmp = icmp eq i32 %and, 0
800 %select = select i1 %cmp, i32 %y, i32 %xor
801 %res = mul i32 %select, %xor ; to bump up use count of the Xor
805 define i32 @shift_no_xor_multiuse_and(i32 %x, i32 %y) {
806 ; CHECK-LABEL: @shift_no_xor_multiuse_and(
807 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
808 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
809 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -3
810 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
811 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[AND2]]
812 ; CHECK-NEXT: ret i32 [[RES]]
815 %cmp = icmp eq i32 %and, 0
816 %and2 = and i32 %y, -3
817 %select = select i1 %cmp, i32 %y, i32 %and2
818 %res = mul i32 %select, %and2 ; to bump up use count of the And
822 define i32 @no_shift_no_xor_multiuse_or(i32 %x, i32 %y) {
823 ; CHECK-LABEL: @no_shift_no_xor_multiuse_or(
824 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
825 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 4096
826 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[AND]], [[Y]]
827 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP1]], [[OR]]
828 ; CHECK-NEXT: ret i32 [[RES]]
830 %and = and i32 %x, 4096
831 %cmp = icmp eq i32 %and, 0
832 %or = or i32 %y, 4096
833 %select = select i1 %cmp, i32 %y, i32 %or
834 %res = mul i32 %select, %or ; to bump up use count of the Or
838 define i32 @no_shift_no_xor_multiuse_xor(i32 %x, i32 %y) {
839 ; CHECK-LABEL: @no_shift_no_xor_multiuse_xor(
840 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
841 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
842 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
843 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
844 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[XOR]]
845 ; CHECK-NEXT: ret i32 [[RES]]
847 %and = and i32 %x, 4096
848 %cmp = icmp eq i32 %and, 0
849 %xor = xor i32 %y, 4096
850 %select = select i1 %cmp, i32 %y, i32 %xor
851 %res = mul i32 %select, %xor ; to bump up use count of the Xor
855 define i32 @no_shift_no_xor_multiuse_and(i32 %x, i32 %y) {
856 ; CHECK-LABEL: @no_shift_no_xor_multiuse_and(
857 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
858 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
859 ; CHECK-NEXT: [[AND2:%.*]] = add i32 [[Y:%.*]], -4097
860 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
861 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[AND2]]
862 ; CHECK-NEXT: ret i32 [[RES]]
864 %and = and i32 %x, 4096
865 %cmp = icmp eq i32 %and, 0
866 %and2 = add i32 %y, -4097
867 %select = select i1 %cmp, i32 %y, i32 %and2
868 %res = mul i32 %select, %and2 ; to bump up use count of the And
872 define i32 @no_shift_xor_multiuse_or(i32 %x, i32 %y) {
873 ; CHECK-LABEL: @no_shift_xor_multiuse_or(
874 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
875 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 4096
876 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[AND]], 4096
877 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y]]
878 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP2]], [[OR]]
879 ; CHECK-NEXT: ret i32 [[RES]]
881 %and = and i32 %x, 4096
882 %cmp = icmp ne i32 0, %and
883 %or = or i32 %y, 4096
884 %select = select i1 %cmp, i32 %y, i32 %or
885 %res = mul i32 %select, %or ; to bump up use count of the Or
889 define i32 @no_shift_xor_multiuse_xor(i32 %x, i32 %y) {
890 ; CHECK-LABEL: @no_shift_xor_multiuse_xor(
891 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
892 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
893 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
894 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 [[Y]]
895 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[XOR]]
896 ; CHECK-NEXT: ret i32 [[RES]]
898 %and = and i32 %x, 4096
899 %cmp = icmp ne i32 0, %and
900 %xor = xor i32 %y, 4096
901 %select = select i1 %cmp, i32 %y, i32 %xor
902 %res = mul i32 %select, %xor ; to bump up use count of the Xor
906 define i32 @no_shift_xor_multiuse_and(i32 %x, i32 %y) {
907 ; CHECK-LABEL: @no_shift_xor_multiuse_and(
908 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
909 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
910 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
911 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[AND2]], i32 [[Y]]
912 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[AND2]]
913 ; CHECK-NEXT: ret i32 [[RES]]
915 %and = and i32 %x, 4096
916 %cmp = icmp ne i32 0, %and
917 %and2 = and i32 %y, -4097
918 %select = select i1 %cmp, i32 %y, i32 %and2
919 %res = mul i32 %select, %and2 ; to bump up use count of the And
923 define i32 @shift_xor_multiuse_or(i32 %x, i32 %y) {
924 ; CHECK-LABEL: @shift_xor_multiuse_or(
925 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
926 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
927 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 2048
928 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[OR]], i32 [[Y]]
929 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[OR]]
930 ; CHECK-NEXT: ret i32 [[RES]]
932 %and = and i32 %x, 4096
933 %cmp = icmp ne i32 0, %and
934 %or = or i32 %y, 2048
935 %select = select i1 %cmp, i32 %y, i32 %or
936 %res = mul i32 %select, %or ; to bump up use count of the Or
940 define i32 @shift_xor_multiuse_xor(i32 %x, i32 %y) {
941 ; CHECK-LABEL: @shift_xor_multiuse_xor(
942 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
943 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
944 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2048
945 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[XOR]], i32 [[Y]]
946 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[XOR]]
947 ; CHECK-NEXT: ret i32 [[RES]]
949 %and = and i32 %x, 4096
950 %cmp = icmp ne i32 0, %and
951 %xor = xor i32 %y, 2048
952 %select = select i1 %cmp, i32 %y, i32 %xor
953 %res = mul i32 %select, %xor ; to bump up use count of the Xor
957 define i32 @shift_xor_multiuse_and(i32 %x, i32 %y) {
958 ; CHECK-LABEL: @shift_xor_multiuse_and(
959 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
960 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
961 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -2049
962 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[AND2]], i32 [[Y]]
963 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[AND2]]
964 ; CHECK-NEXT: ret i32 [[RES]]
966 %and = and i32 %x, 4096
967 %cmp = icmp ne i32 0, %and
968 %and2 = and i32 %y, -2049
969 %select = select i1 %cmp, i32 %y, i32 %and2
970 %res = mul i32 %select, %and2 ; to bump up use count of the and
974 define i32 @shift_no_xor_multiuse_cmp(i32 %x, i32 %y, i32 %z, i32 %w) {
975 ; CHECK-LABEL: @shift_no_xor_multiuse_cmp(
976 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
977 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
978 ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i32 [[AND]], 1
979 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
980 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
981 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP2]], [[SELECT2]]
982 ; CHECK-NEXT: ret i32 [[RES]]
985 %cmp = icmp eq i32 %and, 0
987 %select = select i1 %cmp, i32 %y, i32 %or
988 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
989 %res = mul i32 %select, %select2
993 define i32 @shift_no_xor_multiuse_cmp_with_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
994 ; CHECK-LABEL: @shift_no_xor_multiuse_cmp_with_xor(
995 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
996 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
997 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2
998 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
999 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1000 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1001 ; CHECK-NEXT: ret i32 [[RES]]
1003 %and = and i32 %x, 1
1004 %cmp = icmp eq i32 %and, 0
1005 %xor = xor i32 %y, 2
1006 %select = select i1 %cmp, i32 %y, i32 %xor
1007 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1008 %res = mul i32 %select, %select2
1012 define i32 @shift_no_xor_multiuse_cmp_with_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1013 ; CHECK-LABEL: @shift_no_xor_multiuse_cmp_with_and(
1014 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
1015 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1016 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -3
1017 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1018 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1019 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1020 ; CHECK-NEXT: ret i32 [[RES]]
1022 %and = and i32 %x, 1
1023 %cmp = icmp eq i32 %and, 0
1024 %and2 = and i32 %y, -3
1025 %select = select i1 %cmp, i32 %y, i32 %and2
1026 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1027 %res = mul i32 %select, %select2
1031 define i32 @no_shift_no_xor_multiuse_cmp(i32 %x, i32 %y, i32 %z, i32 %w) {
1032 ; CHECK-LABEL: @no_shift_no_xor_multiuse_cmp(
1033 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1034 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1035 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[AND]], [[Y:%.*]]
1036 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1037 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP1]], [[SELECT2]]
1038 ; CHECK-NEXT: ret i32 [[RES]]
1040 %and = and i32 %x, 4096
1041 %cmp = icmp eq i32 %and, 0
1042 %or = or i32 %y, 4096
1043 %select = select i1 %cmp, i32 %y, i32 %or
1044 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1045 %res = mul i32 %select, %select2
1049 define i32 @no_shift_no_xor_multiuse_cmp_with_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1050 ; CHECK-LABEL: @no_shift_no_xor_multiuse_cmp_with_xor(
1051 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1052 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1053 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
1054 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1055 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1056 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1057 ; CHECK-NEXT: ret i32 [[RES]]
1059 %and = and i32 %x, 4096
1060 %cmp = icmp eq i32 %and, 0
1061 %xor = xor i32 %y, 4096
1062 %select = select i1 %cmp, i32 %y, i32 %xor
1063 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1064 %res = mul i32 %select, %select2
1068 define i32 @no_shift_no_xor_multiuse_cmp_with_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1069 ; CHECK-LABEL: @no_shift_no_xor_multiuse_cmp_with_and(
1070 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1071 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1072 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
1073 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1074 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1075 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1076 ; CHECK-NEXT: ret i32 [[RES]]
1078 %and = and i32 %x, 4096
1079 %cmp = icmp eq i32 %and, 0
1080 %and2 = and i32 %y, -4097
1081 %select = select i1 %cmp, i32 %y, i32 %and2
1082 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1083 %res = mul i32 %select, %select2
1087 define i32 @no_shift_xor_multiuse_cmp(i32 %x, i32 %y, i32 %z, i32 %w) {
1088 ; CHECK-LABEL: @no_shift_xor_multiuse_cmp(
1089 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1090 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1091 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[AND]], 4096
1092 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], [[Y:%.*]]
1093 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[W:%.*]], i32 [[Z:%.*]]
1094 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP2]], [[SELECT2]]
1095 ; CHECK-NEXT: ret i32 [[RES]]
1097 %and = and i32 %x, 4096
1098 %cmp = icmp ne i32 0, %and
1099 %or = or i32 %y, 4096
1100 %select = select i1 %cmp, i32 %y, i32 %or
1101 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1102 %res = mul i32 %select, %select2
1106 define i32 @no_shift_xor_multiuse_cmp_with_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1107 ; CHECK-LABEL: @no_shift_xor_multiuse_cmp_with_xor(
1108 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1109 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1110 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
1111 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1112 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1113 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1114 ; CHECK-NEXT: ret i32 [[RES]]
1116 %and = and i32 %x, 4096
1117 %cmp = icmp ne i32 0, %and
1118 %xor = xor i32 %y, 4096
1119 %select = select i1 %cmp, i32 %y, i32 %xor
1120 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1121 %res = mul i32 %select, %select2
1125 define i32 @no_shift_xor_multiuse_cmp_with_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1126 ; CHECK-LABEL: @no_shift_xor_multiuse_cmp_with_and(
1127 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1128 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1129 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
1130 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1131 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1132 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1133 ; CHECK-NEXT: ret i32 [[RES]]
1135 %and = and i32 %x, 4096
1136 %cmp = icmp ne i32 0, %and
1137 %and2 = and i32 %y, -4097
1138 %select = select i1 %cmp, i32 %y, i32 %and2
1139 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1140 %res = mul i32 %select, %select2
1144 define i32 @shift_xor_multiuse_cmp(i32 %x, i32 %y, i32 %z, i32 %w) {
1145 ; CHECK-LABEL: @shift_xor_multiuse_cmp(
1146 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1147 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1148 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 2048
1149 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[OR]]
1150 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1151 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1152 ; CHECK-NEXT: ret i32 [[RES]]
1154 %and = and i32 %x, 4096
1155 %cmp = icmp ne i32 0, %and
1156 %or = or i32 %y, 2048
1157 %select = select i1 %cmp, i32 %y, i32 %or
1158 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1159 %res = mul i32 %select, %select2
1163 define i32 @shift_xor_multiuse_cmp_with_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1164 ; CHECK-LABEL: @shift_xor_multiuse_cmp_with_xor(
1165 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1166 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1167 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2048
1168 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1169 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1170 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1171 ; CHECK-NEXT: ret i32 [[RES]]
1173 %and = and i32 %x, 4096
1174 %cmp = icmp ne i32 0, %and
1175 %xor = xor i32 %y, 2048
1176 %select = select i1 %cmp, i32 %y, i32 %xor
1177 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1178 %res = mul i32 %select, %select2
1182 define i32 @shift_xor_multiuse_cmp_with_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1183 ; CHECK-LABEL: @shift_xor_multiuse_cmp_with_and(
1184 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1185 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1186 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -2049
1187 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1188 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1189 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1190 ; CHECK-NEXT: ret i32 [[RES]]
1192 %and = and i32 %x, 4096
1193 %cmp = icmp ne i32 0, %and
1194 %and2 = and i32 %y, -2049
1195 %select = select i1 %cmp, i32 %y, i32 %and2
1196 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1197 %res = mul i32 %select, %select2
1201 define i32 @shift_no_xor_multiuse_cmp_or(i32 %x, i32 %y, i32 %z, i32 %w) {
1202 ; CHECK-LABEL: @shift_no_xor_multiuse_cmp_or(
1203 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
1204 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1205 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 2
1206 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[OR]]
1207 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1208 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1209 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[OR]]
1210 ; CHECK-NEXT: ret i32 [[RES2]]
1212 %and = and i32 %x, 1
1213 %cmp = icmp eq i32 %and, 0
1215 %select = select i1 %cmp, i32 %y, i32 %or
1216 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1217 %res = mul i32 %select, %select2
1218 %res2 = mul i32 %res, %or ; to bump up the use count of the or
1222 define i32 @shift_no_xor_multiuse_cmp_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1223 ; CHECK-LABEL: @shift_no_xor_multiuse_cmp_xor(
1224 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
1225 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1226 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2
1227 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1228 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1229 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1230 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[XOR]]
1231 ; CHECK-NEXT: ret i32 [[RES2]]
1233 %and = and i32 %x, 1
1234 %cmp = icmp eq i32 %and, 0
1235 %xor = xor i32 %y, 2
1236 %select = select i1 %cmp, i32 %y, i32 %xor
1237 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1238 %res = mul i32 %select, %select2
1239 %res2 = mul i32 %res, %xor ; to bump up the use count of the xor
1243 define i32 @shift_no_xor_multiuse_cmp_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1244 ; CHECK-LABEL: @shift_no_xor_multiuse_cmp_and(
1245 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 1
1246 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1247 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -3
1248 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1249 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1250 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1251 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[AND2]]
1252 ; CHECK-NEXT: ret i32 [[RES2]]
1254 %and = and i32 %x, 1
1255 %cmp = icmp eq i32 %and, 0
1256 %and2 = and i32 %y, -3
1257 %select = select i1 %cmp, i32 %y, i32 %and2
1258 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1259 %res = mul i32 %select, %select2
1260 %res2 = mul i32 %res, %and2 ; to bump up the use count of the and
1264 define i32 @no_shift_no_xor_multiuse_cmp_or(i32 %x, i32 %y, i32 %z, i32 %w) {
1265 ; CHECK-LABEL: @no_shift_no_xor_multiuse_cmp_or(
1266 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1267 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1268 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 4096
1269 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[AND]], [[Y]]
1270 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1271 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[TMP1]], [[SELECT2]]
1272 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[OR]]
1273 ; CHECK-NEXT: ret i32 [[RES2]]
1275 %and = and i32 %x, 4096
1276 %cmp = icmp eq i32 %and, 0
1277 %or = or i32 %y, 4096
1278 %select = select i1 %cmp, i32 %y, i32 %or
1279 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1280 %res = mul i32 %select, %select2
1281 %res2 = mul i32 %res, %or ; to bump up the use count of the or
1285 define i32 @no_shift_no_xor_multiuse_cmp_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1286 ; CHECK-LABEL: @no_shift_no_xor_multiuse_cmp_xor(
1287 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1288 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1289 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
1290 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1291 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1292 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1293 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[XOR]]
1294 ; CHECK-NEXT: ret i32 [[RES2]]
1296 %and = and i32 %x, 4096
1297 %cmp = icmp eq i32 %and, 0
1298 %xor = xor i32 %y, 4096
1299 %select = select i1 %cmp, i32 %y, i32 %xor
1300 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1301 %res = mul i32 %select, %select2
1302 %res2 = mul i32 %res, %xor ; to bump up the use count of the xor
1306 define i32 @no_shift_no_xor_multiuse_cmp_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1307 ; CHECK-LABEL: @no_shift_no_xor_multiuse_cmp_and(
1308 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1309 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], 0
1310 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
1311 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1312 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1313 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1314 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[AND2]]
1315 ; CHECK-NEXT: ret i32 [[RES2]]
1317 %and = and i32 %x, 4096
1318 %cmp = icmp eq i32 %and, 0
1319 %and2 = and i32 %y, -4097
1320 %select = select i1 %cmp, i32 %y, i32 %and2
1321 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1322 %res = mul i32 %select, %select2
1323 %res2 = mul i32 %res, %and2 ; to bump up the use count of the and
1327 define i32 @no_shift_xor_multiuse_cmp_or(i32 %x, i32 %y, i32 %z, i32 %w) {
1328 ; CHECK-LABEL: @no_shift_xor_multiuse_cmp_or(
1329 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1330 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1331 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 4096
1332 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[OR]]
1333 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1334 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1335 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[OR]]
1336 ; CHECK-NEXT: ret i32 [[RES2]]
1338 %and = and i32 %x, 4096
1339 %cmp = icmp ne i32 0, %and
1340 %or = or i32 %y, 4096
1341 %select = select i1 %cmp, i32 %y, i32 %or
1342 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1343 %res = mul i32 %select, %select2
1344 %res2 = mul i32 %res, %or ; to bump up the use count of the or
1348 define i32 @no_shift_xor_multiuse_cmp_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1349 ; CHECK-LABEL: @no_shift_xor_multiuse_cmp_xor(
1350 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1351 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1352 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 4096
1353 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1354 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1355 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1356 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[XOR]]
1357 ; CHECK-NEXT: ret i32 [[RES2]]
1359 %and = and i32 %x, 4096
1360 %cmp = icmp ne i32 0, %and
1361 %xor = xor i32 %y, 4096
1362 %select = select i1 %cmp, i32 %y, i32 %xor
1363 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1364 %res = mul i32 %select, %select2
1365 %res2 = mul i32 %res, %xor ; to bump up the use count of the xor
1369 define i32 @no_shift_xor_multiuse_cmp_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1370 ; CHECK-LABEL: @no_shift_xor_multiuse_cmp_and(
1371 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1372 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1373 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], -4097
1374 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1375 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1376 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1377 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[AND2]]
1378 ; CHECK-NEXT: ret i32 [[RES2]]
1380 %and = and i32 %x, 4096
1381 %cmp = icmp ne i32 0, %and
1382 %and2 = and i32 %y, -4097
1383 %select = select i1 %cmp, i32 %y, i32 %and2
1384 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1385 %res = mul i32 %select, %select2
1386 %res2 = mul i32 %res, %and2 ; to bump up the use count of the and
1390 define i32 @shift_xor_multiuse_cmp_or(i32 %x, i32 %y, i32 %z, i32 %w) {
1391 ; CHECK-LABEL: @shift_xor_multiuse_cmp_or(
1392 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1393 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1394 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], 2048
1395 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[OR]]
1396 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1397 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1398 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[OR]]
1399 ; CHECK-NEXT: ret i32 [[RES2]]
1401 %and = and i32 %x, 4096
1402 %cmp = icmp ne i32 0, %and
1403 %or = or i32 %y, 2048
1404 %select = select i1 %cmp, i32 %y, i32 %or
1405 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1406 %res = mul i32 %select, %select2
1407 %res2 = mul i32 %res, %or ; to bump up the use count of the or
1411 define i32 @shift_xor_multiuse_cmp_xor(i32 %x, i32 %y, i32 %z, i32 %w) {
1412 ; CHECK-LABEL: @shift_xor_multiuse_cmp_xor(
1413 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1414 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1415 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], 2048
1416 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[XOR]]
1417 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1418 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1419 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[XOR]]
1420 ; CHECK-NEXT: ret i32 [[RES2]]
1422 %and = and i32 %x, 4096
1423 %cmp = icmp ne i32 0, %and
1424 %xor = xor i32 %y, 2048
1425 %select = select i1 %cmp, i32 %y, i32 %xor
1426 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1427 %res = mul i32 %select, %select2
1428 %res2 = mul i32 %res, %xor ; to bump up the use count of the xor
1432 define i32 @shift_xor_multiuse_cmp_and(i32 %x, i32 %y, i32 %z, i32 %w) {
1433 ; CHECK-LABEL: @shift_xor_multiuse_cmp_and(
1434 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 4096
1435 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[AND]], 0
1436 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[Y:%.*]], 2048
1437 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[AND2]]
1438 ; CHECK-NEXT: [[SELECT2:%.*]] = select i1 [[CMP]], i32 [[Z:%.*]], i32 [[W:%.*]]
1439 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[SELECT]], [[SELECT2]]
1440 ; CHECK-NEXT: [[RES2:%.*]] = mul i32 [[RES]], [[AND2]]
1441 ; CHECK-NEXT: ret i32 [[RES2]]
1443 %and = and i32 %x, 4096
1444 %cmp = icmp ne i32 0, %and
1445 %and2 = and i32 %y, 2048
1446 %select = select i1 %cmp, i32 %y, i32 %and2
1447 %select2 = select i1 %cmp, i32 %z, i32 %w ; to bump up use count of the cmp
1448 %res = mul i32 %select, %select2
1449 %res2 = mul i32 %res, %and2 ; to bump up the use count of the and