[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / test / Transforms / InstCombine / or-xor.ll
blobe91a7a3c5fa38f874e6d39c8c9093f6673c05647
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 ; X | ~(X | Y) --> X | ~Y
6 define i32 @test1(i32 %x, i32 %y) {
7 ; CHECK-LABEL: @test1(
8 ; CHECK-NEXT:    [[Y_NOT:%.*]] = xor i32 [[Y:%.*]], -1
9 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[Y_NOT]], [[X:%.*]]
10 ; CHECK-NEXT:    ret i32 [[Z]]
12   %or = or i32 %x, %y
13   %not = xor i32 %or, -1
14   %z = or i32 %x, %not
15   ret i32 %z
18 ; Commute (rename) the inner 'or' operands:
19 ; Y | ~(X | Y) --> ~X | Y
21 define i32 @test2(i32 %x, i32 %y) {
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT:    [[X_NOT:%.*]] = xor i32 [[X:%.*]], -1
24 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[X_NOT]], [[Y:%.*]]
25 ; CHECK-NEXT:    ret i32 [[Z]]
27   %or = or i32 %x, %y
28   %not = xor i32 %or, -1
29   %z = or i32 %y, %not
30   ret i32 %z
33 ; X | ~(X ^ Y) --> X | ~Y
35 define i32 @test3(i32 %x, i32 %y) {
36 ; CHECK-LABEL: @test3(
37 ; CHECK-NEXT:    [[Y_NOT:%.*]] = xor i32 [[Y:%.*]], -1
38 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[Y_NOT]], [[X:%.*]]
39 ; CHECK-NEXT:    ret i32 [[Z]]
41   %xor = xor i32 %x, %y
42   %not = xor i32 %xor, -1
43   %z = or i32 %x, %not
44   ret i32 %z
47 ; Commute (rename) the 'xor' operands:
48 ; Y | ~(X ^ Y) --> ~X | Y
50 define i32 @test4(i32 %x, i32 %y) {
51 ; CHECK-LABEL: @test4(
52 ; CHECK-NEXT:    [[X_NOT:%.*]] = xor i32 [[X:%.*]], -1
53 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[X_NOT]], [[Y:%.*]]
54 ; CHECK-NEXT:    ret i32 [[Z]]
56   %xor = xor i32 %x, %y
57   %not = xor i32 %xor, -1
58   %z = or i32 %y, %not
59   ret i32 %z
62 ; (X ^ Y) | ~X  --> ~(X & Y)
64 define i32 @test5(i32 %x, i32 %y) {
65 ; CHECK-LABEL: @test5(
66 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
67 ; CHECK-NEXT:    [[Z:%.*]] = xor i32 [[TMP1]], -1
68 ; CHECK-NEXT:    ret i32 [[Z]]
70   %xor = xor i32 %x, %y
71   %notx = xor i32 %x, -1
72   %z = or i32 %xor, %notx
73   ret i32 %z
76 ; Commute the 'or' operands
77 ; ~X | (X ^ Y) --> ~(X & Y)
79 define <2 x i4> @test5_commuted(<2 x i4> %x, <2 x i4> %y) {
80 ; CHECK-LABEL: @test5_commuted(
81 ; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i4> [[X:%.*]], [[Y:%.*]]
82 ; CHECK-NEXT:    [[Z:%.*]] = xor <2 x i4> [[TMP1]], <i4 -1, i4 -1>
83 ; CHECK-NEXT:    ret <2 x i4> [[Z]]
85   %xor = xor <2 x i4> %x, %y
86   %notx = xor <2 x i4> %x, <i4 -1, i4 -1>
87   %z = or <2 x i4> %notx, %xor
88   ret <2 x i4> %z
91 ; Commute the inner 'xor' operands
92 ; (Y ^ X) | ~X  --> ~(Y & X)
94 define i64 @test5_commuted_x_y(i64 %x, i64 %y) {
95 ; CHECK-LABEL: @test5_commuted_x_y(
96 ; CHECK-NEXT:    [[TMP1:%.*]] = and i64 [[Y:%.*]], [[X:%.*]]
97 ; CHECK-NEXT:    [[Z:%.*]] = xor i64 [[TMP1]], -1
98 ; CHECK-NEXT:    ret i64 [[Z]]
100   %xor = xor i64 %y, %x
101   %notx = xor i64 %x, -1
102   %z = or i64  %xor, %notx
103   ret i64 %z
107 define i8 @test5_extra_use_not(i8 %x, i8 %y, i8* %dst) {
108 ; CHECK-LABEL: @test5_extra_use_not(
109 ; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
110 ; CHECK-NEXT:    store i8 [[NOTX]], i8* [[DST:%.*]], align 1
111 ; CHECK-NEXT:    [[TMP1:%.*]] = and i8 [[X]], [[Y:%.*]]
112 ; CHECK-NEXT:    [[Z:%.*]] = xor i8 [[TMP1]], -1
113 ; CHECK-NEXT:    ret i8 [[Z]]
115   %xor = xor i8 %x, %y
116   %notx = xor i8 %x, -1
117   store i8 %notx, i8* %dst
118   %z = or i8 %notx, %xor
119   ret i8 %z
123 define i65 @test5_extra_use_xor(i65 %x, i65 %y, i65* %dst) {
124 ; CHECK-LABEL: @test5_extra_use_xor(
125 ; CHECK-NEXT:    [[XOR:%.*]] = xor i65 [[X:%.*]], [[Y:%.*]]
126 ; CHECK-NEXT:    store i65 [[XOR]], i65* [[DST:%.*]], align 4
127 ; CHECK-NEXT:    [[TMP1:%.*]] = and i65 [[X]], [[Y]]
128 ; CHECK-NEXT:    [[Z:%.*]] = xor i65 [[TMP1]], -1
129 ; CHECK-NEXT:    ret i65 [[Z]]
131   %xor = xor i65 %x, %y
132   store i65 %xor, i65* %dst
133   %notx = xor i65 %x, -1
134   %z = or i65 %notx, %xor
135   ret i65 %z
138 define i16 @test5_extra_use_not_xor(i16 %x, i16 %y, i16* %dst_not, i16* %dst_xor) {
139 ; CHECK-LABEL: @test5_extra_use_not_xor(
140 ; CHECK-NEXT:    [[XOR:%.*]] = xor i16 [[X:%.*]], [[Y:%.*]]
141 ; CHECK-NEXT:    store i16 [[XOR]], i16* [[DST_XOR:%.*]], align 2
142 ; CHECK-NEXT:    [[NOTX:%.*]] = xor i16 [[X]], -1
143 ; CHECK-NEXT:    store i16 [[NOTX]], i16* [[DST_NOT:%.*]], align 2
144 ; CHECK-NEXT:    [[Z:%.*]] = or i16 [[XOR]], [[NOTX]]
145 ; CHECK-NEXT:    ret i16 [[Z]]
147   %xor = xor i16 %x, %y
148   store i16 %xor, i16* %dst_xor
149   %notx = xor i16 %x, -1
150   store i16 %notx, i16* %dst_not
151   %z = or i16 %notx, %xor
152   ret i16 %z
155 define i32 @test7(i32 %x, i32 %y) {
156 ; CHECK-LABEL: @test7(
157 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
158 ; CHECK-NEXT:    ret i32 [[Z]]
160   %xor = xor i32 %x, %y
161   %z = or i32 %y, %xor
162   ret i32 %z
165 define i32 @test8(i32 %x, i32 %y) {
166 ; CHECK-LABEL: @test8(
167 ; CHECK-NEXT:    [[X_NOT:%.*]] = xor i32 [[X:%.*]], -1
168 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[X_NOT]], [[Y:%.*]]
169 ; CHECK-NEXT:    ret i32 [[Z]]
171   %not = xor i32 %y, -1
172   %xor = xor i32 %x, %not
173   %z = or i32 %y, %xor
174   ret i32 %z
177 define i32 @test9(i32 %x, i32 %y) {
178 ; CHECK-LABEL: @test9(
179 ; CHECK-NEXT:    [[Y_NOT:%.*]] = xor i32 [[Y:%.*]], -1
180 ; CHECK-NEXT:    [[Z:%.*]] = or i32 [[Y_NOT]], [[X:%.*]]
181 ; CHECK-NEXT:    ret i32 [[Z]]
183   %not = xor i32 %x, -1
184   %xor = xor i32 %not, %y
185   %z = or i32 %x, %xor
186   ret i32 %z
189 ; (A ^ B) | (~A ^ B) --> -1
191 define i32 @test10(i32 %A, i32 %B) {
192 ; CHECK-LABEL: @test10(
193 ; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
194 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[A]], [[B]]
195 ; CHECK-NEXT:    [[XOR2:%.*]] = xor i32 [[TMP1]], -1
196 ; CHECK-NEXT:    [[OR:%.*]] = or i32 [[XOR1]], [[XOR2]]
197 ; CHECK-NEXT:    ret i32 [[OR]]
199   %xor1 = xor i32 %B, %A
200   %not = xor i32 %A, -1
201   %xor2 = xor i32 %not, %B
202   %or = or i32 %xor1, %xor2
203   ret i32 %or
206 define i32 @test10_commuted(i32 %A, i32 %B) {
207 ; CHECK-LABEL: @test10_commuted(
208 ; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
209 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[A]], [[B]]
210 ; CHECK-NEXT:    [[XOR2:%.*]] = xor i32 [[TMP1]], -1
211 ; CHECK-NEXT:    [[OR:%.*]] = or i32 [[XOR1]], [[XOR2]]
212 ; CHECK-NEXT:    ret i32 [[OR]]
214   %xor1 = xor i32 %B, %A
215   %not = xor i32 %A, -1
216   %xor2 = xor i32 %not, %B
217   %or = or i32 %xor2, %xor1
218   ret i32 %or
221 define i32 @test10_extrause(i32 %A, i32 %B, i32* %dst) {
222 ; CHECK-LABEL: @test10_extrause(
223 ; CHECK-NEXT:    [[NOT:%.*]] = xor i32 [[A:%.*]], -1
224 ; CHECK-NEXT:    store i32 [[NOT]], i32* [[DST:%.*]], align 4
225 ; CHECK-NEXT:    ret i32 -1
227   %xor1 = xor i32 %B, %A
228   %not = xor i32 %A, -1
229   store i32 %not, i32* %dst
230   %xor2 = xor i32 %not, %B
231   %or = or i32 %xor1, %xor2
232   ret i32 %or
235 define i32 @test10_commuted_extrause(i32 %A, i32 %B, i32* %dst) {
236 ; CHECK-LABEL: @test10_commuted_extrause(
237 ; CHECK-NEXT:    [[NOT:%.*]] = xor i32 [[A:%.*]], -1
238 ; CHECK-NEXT:    store i32 [[NOT]], i32* [[DST:%.*]], align 4
239 ; CHECK-NEXT:    ret i32 -1
241   %xor1 = xor i32 %B, %A
242   %not = xor i32 %A, -1
243   store i32 %not, i32* %dst
244   %xor2 = xor i32 %not, %B
245   %or = or i32 %xor2, %xor1
246   ret i32 %or
249 ; (A ^ B) | ~(A ^ B) --> -1
250 define i32 @test10_canonical(i32 %A, i32 %B) {
251 ; CHECK-LABEL: @test10_canonical(
252 ; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
253 ; CHECK-NEXT:    [[XOR2:%.*]] = xor i32 [[A]], [[B]]
254 ; CHECK-NEXT:    [[NOT:%.*]] = xor i32 [[XOR2]], -1
255 ; CHECK-NEXT:    [[OR:%.*]] = or i32 [[XOR1]], [[NOT]]
256 ; CHECK-NEXT:    ret i32 [[OR]]
258   %xor1 = xor i32 %B, %A
259   %xor2 = xor i32 %A, %B
260   %not = xor i32 %xor2, -1
261   %or = or i32 %xor1, %not
262   ret i32 %or
265 ; (x | y) & ((~x) ^ y) -> (x & y)
266 define i32 @test11(i32 %x, i32 %y) {
267 ; CHECK-LABEL: @test11(
268 ; CHECK-NEXT:    [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
269 ; CHECK-NEXT:    ret i32 [[AND]]
271   %or = or i32 %x, %y
272   %neg = xor i32 %x, -1
273   %xor = xor i32 %neg, %y
274   %and = and i32 %or, %xor
275   ret i32 %and
278 ; ((~x) ^ y) & (x | y) -> (x & y)
279 define i32 @test12(i32 %x, i32 %y) {
280 ; CHECK-LABEL: @test12(
281 ; CHECK-NEXT:    [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
282 ; CHECK-NEXT:    ret i32 [[AND]]
284   %neg = xor i32 %x, -1
285   %xor = xor i32 %neg, %y
286   %or = or i32 %x, %y
287   %and = and i32 %xor, %or
288   ret i32 %and
291 define i32 @test12_commuted(i32 %x, i32 %y) {
292 ; CHECK-LABEL: @test12_commuted(
293 ; CHECK-NEXT:    [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
294 ; CHECK-NEXT:    ret i32 [[AND]]
296   %neg = xor i32 %x, -1
297   %xor = xor i32 %neg, %y
298   %or = or i32 %y, %x
299   %and = and i32 %xor, %or
300   ret i32 %and
303 ; ((x | y) ^ (x ^ y)) -> (x & y)
304 define i32 @test13(i32 %x, i32 %y) {
305 ; CHECK-LABEL: @test13(
306 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
307 ; CHECK-NEXT:    ret i32 [[TMP1]]
309   %1 = xor i32 %y, %x
310   %2 = or i32 %y, %x
311   %3 = xor i32 %2, %1
312   ret i32 %3
315 ; ((x | ~y) ^ (~x | y)) -> x ^ y
316 define i32 @test14(i32 %x, i32 %y) {
317 ; CHECK-LABEL: @test14(
318 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
319 ; CHECK-NEXT:    ret i32 [[XOR]]
321   %noty = xor i32 %y, -1
322   %notx = xor i32 %x, -1
323   %or1 = or i32 %x, %noty
324   %or2 = or i32 %notx, %y
325   %xor = xor i32 %or1, %or2
326   ret i32 %xor
329 define i32 @test14_commuted(i32 %x, i32 %y) {
330 ; CHECK-LABEL: @test14_commuted(
331 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
332 ; CHECK-NEXT:    ret i32 [[XOR]]
334   %noty = xor i32 %y, -1
335   %notx = xor i32 %x, -1
336   %or1 = or i32 %noty, %x
337   %or2 = or i32 %notx, %y
338   %xor = xor i32 %or1, %or2
339   ret i32 %xor
342 ; ((x & ~y) ^ (~x & y)) -> x ^ y
343 define i32 @test15(i32 %x, i32 %y) {
344 ; CHECK-LABEL: @test15(
345 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
346 ; CHECK-NEXT:    ret i32 [[XOR]]
348   %noty = xor i32 %y, -1
349   %notx = xor i32 %x, -1
350   %and1 = and i32 %x, %noty
351   %and2 = and i32 %notx, %y
352   %xor = xor i32 %and1, %and2
353   ret i32 %xor
356 define i32 @test15_commuted(i32 %x, i32 %y) {
357 ; CHECK-LABEL: @test15_commuted(
358 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
359 ; CHECK-NEXT:    ret i32 [[XOR]]
361   %noty = xor i32 %y, -1
362   %notx = xor i32 %x, -1
363   %and1 = and i32 %noty, %x
364   %and2 = and i32 %notx, %y
365   %xor = xor i32 %and1, %and2
366   ret i32 %xor
369 ; ((a ^ b) & C1) | (b & C2) -> (a & C1) ^ b iff C1 == ~C2
371 define i32 @or_and_xor_not_constant_commute0(i32 %a, i32 %b) {
372 ; CHECK-LABEL: @or_and_xor_not_constant_commute0(
373 ; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[A:%.*]], 1
374 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[TMP1]], [[B:%.*]]
375 ; CHECK-NEXT:    ret i32 [[XOR]]
377   %or = xor i32 %a, %b
378   %and1 = and i32 %or, 1
379   %and2 = and i32 %b, -2
380   %xor = or i32 %and1, %and2
381   ret i32 %xor
384 define i9 @or_and_xor_not_constant_commute1(i9 %a, i9 %b) {
385 ; CHECK-LABEL: @or_and_xor_not_constant_commute1(
386 ; CHECK-NEXT:    [[TMP1:%.*]] = and i9 [[A:%.*]], 42
387 ; CHECK-NEXT:    [[XOR:%.*]] = xor i9 [[TMP1]], [[B:%.*]]
388 ; CHECK-NEXT:    ret i9 [[XOR]]
390   %or = xor i9 %b, %a
391   %and1 = and i9 %or, 42
392   %and2 = and i9 %b, -43
393   %xor = or i9 %and1, %and2
394   ret i9 %xor
397 define <2 x i9> @or_and_xor_not_constant_commute2_splat(<2 x i9> %a, <2 x i9> %b) {
398 ; CHECK-LABEL: @or_and_xor_not_constant_commute2_splat(
399 ; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i9> [[A:%.*]], <i9 42, i9 42>
400 ; CHECK-NEXT:    [[XOR:%.*]] = xor <2 x i9> [[TMP1]], [[B:%.*]]
401 ; CHECK-NEXT:    ret <2 x i9> [[XOR]]
403   %or = xor <2 x i9> %b, %a
404   %and1 = and <2 x i9> %or, <i9 42, i9 42>
405   %and2 = and <2 x i9> %b, <i9 -43, i9 -43>
406   %xor = or <2 x i9> %and2, %and1
407   ret <2 x i9> %xor
410 define <2 x i9> @or_and_xor_not_constant_commute3_splat(<2 x i9> %a, <2 x i9> %b) {
411 ; CHECK-LABEL: @or_and_xor_not_constant_commute3_splat(
412 ; CHECK-NEXT:    [[TMP1:%.*]] = and <2 x i9> [[A:%.*]], <i9 42, i9 42>
413 ; CHECK-NEXT:    [[XOR:%.*]] = xor <2 x i9> [[TMP1]], [[B:%.*]]
414 ; CHECK-NEXT:    ret <2 x i9> [[XOR]]
416   %or = xor <2 x i9> %a, %b
417   %and1 = and <2 x i9> %or, <i9 42, i9 42>
418   %and2 = and <2 x i9> %b, <i9 -43, i9 -43>
419   %xor = or <2 x i9> %and2, %and1
420   ret <2 x i9> %xor
423 define i8 @not_or(i8 %x) {
424 ; CHECK-LABEL: @not_or(
425 ; CHECK-NEXT:    [[NOTX:%.*]] = xor i8 [[X:%.*]], -1
426 ; CHECK-NEXT:    [[OR:%.*]] = or i8 [[NOTX]], 7
427 ; CHECK-NEXT:    ret i8 [[OR]]
429   %notx = xor i8 %x, -1
430   %or = or i8 %notx, 7
431   ret i8 %or
434 define i8 @not_or_xor(i8 %x) {
435 ; CHECK-LABEL: @not_or_xor(
436 ; CHECK-NEXT:    [[TMP1:%.*]] = and i8 [[X:%.*]], -8
437 ; CHECK-NEXT:    [[XOR:%.*]] = xor i8 [[TMP1]], -13
438 ; CHECK-NEXT:    ret i8 [[XOR]]
440   %notx = xor i8 %x, -1
441   %or = or i8 %notx, 7
442   %xor = xor i8 %or, 12
443   ret i8 %xor
446 define i8 @xor_or(i8 %x) {
447 ; CHECK-LABEL: @xor_or(
448 ; CHECK-NEXT:    [[TMP1:%.*]] = or i8 [[X:%.*]], 7
449 ; CHECK-NEXT:    [[OR:%.*]] = xor i8 [[TMP1]], 32
450 ; CHECK-NEXT:    ret i8 [[OR]]
452   %xor = xor i8 %x, 32
453   %or = or i8 %xor, 7
454   ret i8 %or
457 define i8 @xor_or2(i8 %x) {
458 ; CHECK-LABEL: @xor_or2(
459 ; CHECK-NEXT:    [[TMP1:%.*]] = or i8 [[X:%.*]], 7
460 ; CHECK-NEXT:    [[OR:%.*]] = xor i8 [[TMP1]], 32
461 ; CHECK-NEXT:    ret i8 [[OR]]
463   %xor = xor i8 %x, 33
464   %or = or i8 %xor, 7
465   ret i8 %or
468 define i8 @xor_or_xor(i8 %x) {
469 ; CHECK-LABEL: @xor_or_xor(
470 ; CHECK-NEXT:    [[TMP1:%.*]] = or i8 [[X:%.*]], 7
471 ; CHECK-NEXT:    [[XOR2:%.*]] = xor i8 [[TMP1]], 44
472 ; CHECK-NEXT:    ret i8 [[XOR2]]
474   %xor1 = xor i8 %x, 33
475   %or = or i8 %xor1, 7
476   %xor2 = xor i8 %or, 12
477   ret i8 %xor2
480 define i8 @or_xor_or(i8 %x) {
481 ; CHECK-LABEL: @or_xor_or(
482 ; CHECK-NEXT:    [[TMP1:%.*]] = or i8 [[X:%.*]], 39
483 ; CHECK-NEXT:    [[OR2:%.*]] = xor i8 [[TMP1]], 8
484 ; CHECK-NEXT:    ret i8 [[OR2]]
486   %or1 = or i8 %x, 33
487   %xor = xor i8 %or1, 12
488   %or2 = or i8 %xor, 7
489   ret i8 %or2
492 define i8 @test17(i8 %A, i8 %B) {
493 ; CHECK-LABEL: @test17(
494 ; CHECK-NEXT:    [[XOR1:%.*]] = xor i8 [[B:%.*]], [[A:%.*]]
495 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[A]], [[B]]
496 ; CHECK-NEXT:    [[XOR2:%.*]] = xor i8 [[TMP1]], 33
497 ; CHECK-NEXT:    [[OR:%.*]] = or i8 [[XOR1]], [[XOR2]]
498 ; CHECK-NEXT:    [[RES:%.*]] = mul i8 [[OR]], [[XOR2]]
499 ; CHECK-NEXT:    ret i8 [[RES]]
501   %xor1 = xor i8 %B, %A
502   %not = xor i8 %A, 33
503   %xor2 = xor i8 %not, %B
504   %or = or i8 %xor1, %xor2
505   %res = mul i8 %or, %xor2 ; to increase the use count for the xor
506   ret i8 %res
509 define i8 @test18(i8 %A, i8 %B) {
510 ; CHECK-LABEL: @test18(
511 ; CHECK-NEXT:    [[XOR1:%.*]] = xor i8 [[B:%.*]], [[A:%.*]]
512 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[A]], [[B]]
513 ; CHECK-NEXT:    [[XOR2:%.*]] = xor i8 [[TMP1]], 33
514 ; CHECK-NEXT:    [[OR:%.*]] = or i8 [[XOR2]], [[XOR1]]
515 ; CHECK-NEXT:    [[RES:%.*]] = mul i8 [[OR]], [[XOR2]]
516 ; CHECK-NEXT:    ret i8 [[RES]]
518   %xor1 = xor i8 %B, %A
519   %not = xor i8 %A, 33
520   %xor2 = xor i8 %not, %B
521   %or = or i8 %xor2, %xor1
522   %res = mul i8 %or, %xor2 ; to increase the use count for the xor
523   ret i8 %res
526 ; ((x | y) ^ (~x | ~y)) -> ~(x ^ y)
527 define i32 @test19(i32 %x, i32 %y) {
528 ; CHECK-LABEL: @test19(
529 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
530 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[TMP1]], -1
531 ; CHECK-NEXT:    ret i32 [[XOR]]
533   %noty = xor i32 %y, -1
534   %notx = xor i32 %x, -1
535   %or1 = or i32 %x, %y
536   %or2 = or i32 %notx, %noty
537   %xor = xor i32 %or1, %or2
538   ret i32 %xor
541 ; ((x | y) ^ (~y | ~x)) -> ~(x ^ y)
542 define i32 @test20(i32 %x, i32 %y) {
543 ; CHECK-LABEL: @test20(
544 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
545 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[TMP1]], -1
546 ; CHECK-NEXT:    ret i32 [[XOR]]
548   %noty = xor i32 %y, -1
549   %notx = xor i32 %x, -1
550   %or1 = or i32 %x, %y
551   %or2 = or i32 %noty, %notx
552   %xor = xor i32 %or1, %or2
553   ret i32 %xor
556 ; ((~x | ~y) ^ (x | y)) -> ~(x ^ y)
557 define i32 @test21(i32 %x, i32 %y) {
558 ; CHECK-LABEL: @test21(
559 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
560 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[TMP1]], -1
561 ; CHECK-NEXT:    ret i32 [[XOR]]
563   %noty = xor i32 %y, -1
564   %notx = xor i32 %x, -1
565   %or1 = or i32 %notx, %noty
566   %or2 = or i32 %x, %y
567   %xor = xor i32 %or1, %or2
568   ret i32 %xor
571 ; ((~x | ~y) ^ (y | x)) -> ~(x ^ y)
572 define i32 @test22(i32 %x, i32 %y) {
573 ; CHECK-LABEL: @test22(
574 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[Y:%.*]], [[X:%.*]]
575 ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[TMP1]], -1
576 ; CHECK-NEXT:    ret i32 [[XOR]]
578   %noty = xor i32 %y, -1
579   %notx = xor i32 %x, -1
580   %or1 = or i32 %notx, %noty
581   %or2 = or i32 %y, %x
582   %xor = xor i32 %or1, %or2
583   ret i32 %xor
586 ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
587 define i8 @test23(i8 %A) {
588 ; CHECK-LABEL: @test23(
589 ; CHECK-NEXT:    ret i8 -1
591   %B = or i8 %A, -2
592   %C = xor i8 %B, 13
593   %D = or i8 %C, 1
594   %E = xor i8 %D, 12
595   ret i8 %E
598 define i8 @test23v(<2 x i8> %A) {
599 ; CHECK-LABEL: @test23v(
600 ; CHECK-NEXT:    ret i8 -1
602   %B = or <2 x i8> %A, <i8 -2, i8 0>
603   %CV = xor <2 x i8> %B, <i8 13, i8 13>
604   %C = extractelement <2 x i8> %CV, i32 0
605   %D = or i8 %C, 1
606   %E = xor i8 %D, 12
607   ret i8 %E
610 ; ~(a | b) | (~a & b);
611 define i32 @PR45977_f1(i32 %a, i32 %b) {
612 ; CHECK-LABEL: @PR45977_f1(
613 ; CHECK-NEXT:    [[NOT:%.*]] = xor i32 [[A:%.*]], -1
614 ; CHECK-NEXT:    ret i32 [[NOT]]
616   %not = xor i32 %a, -1
617   %andnot = and i32 %not, %b
618   %or = or i32 %a, %b
619   %notor = xor i32 %or, -1
620   %res = or i32 %notor, %andnot
621   ret i32 %res
624 ; (a | b) ^ (a | ~b)
625 define i32 @PR45977_f2(i32 %a, i32 %b) {
626 ; CHECK-LABEL: @PR45977_f2(
627 ; CHECK-NEXT:    [[TMP1:%.*]] = xor i32 [[A:%.*]], -1
628 ; CHECK-NEXT:    ret i32 [[TMP1]]
630   %or = or i32 %a, %b
631   %not = xor i32 %b, -1
632   %ornot = or i32 %a, %not
633   %res = xor i32 %or, %ornot
634   ret i32 %res