1 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 define i32 @test1(i32 %x, i32 %y) nounwind {
9 ; CHECK-NEXT: %y.not = xor i32 %y, -1
10 ; CHECK-NEXT: %z = or i32 %y.not, %x
11 ; CHECK-NEXT: ret i32 %z
14 define i32 @test2(i32 %x, i32 %y) nounwind {
16 %not = xor i32 %or, -1
19 ; CHECK-LABEL: @test2(
20 ; CHECK-NEXT: %x.not = xor i32 %x, -1
21 ; CHECK-NEXT: %z = or i32 %x.not, %y
22 ; CHECK-NEXT: ret i32 %z
25 define i32 @test3(i32 %x, i32 %y) nounwind {
27 %not = xor i32 %xor, -1
30 ; CHECK-LABEL: @test3(
31 ; CHECK-NEXT: %y.not = xor i32 %y, -1
32 ; CHECK-NEXT: %z = or i32 %y.not, %x
33 ; CHECK-NEXT: ret i32 %z
36 define i32 @test4(i32 %x, i32 %y) nounwind {
38 %not = xor i32 %xor, -1
41 ; CHECK-LABEL: @test4(
42 ; CHECK-NEXT: %x.not = xor i32 %x, -1
43 ; CHECK-NEXT: %z = or i32 %x.not, %y
44 ; CHECK-NEXT: ret i32 %z
47 define i32 @test5(i32 %x, i32 %y) nounwind {
49 %not = xor i32 %and, -1
52 ; CHECK-LABEL: @test5(
53 ; CHECK-NEXT: ret i32 -1
56 define i32 @test6(i32 %x, i32 %y) nounwind {
58 %not = xor i32 %and, -1
61 ; CHECK-LABEL: @test6(
62 ; CHECK-NEXT: ret i32 -1
65 define i32 @test7(i32 %x, i32 %y) nounwind {
69 ; CHECK-LABEL: @test7(
70 ; CHECK-NEXT: %z = or i32 %x, %y
71 ; CHECK-NEXT: ret i32 %z
74 define i32 @test8(i32 %x, i32 %y) nounwind {
76 %xor = xor i32 %x, %not
79 ; CHECK-LABEL: @test8(
80 ; CHECK-NEXT: %x.not = xor i32 %x, -1
81 ; CHECK-NEXT: %z = or i32 %x.not, %y
82 ; CHECK-NEXT: ret i32 %z
85 define i32 @test9(i32 %x, i32 %y) nounwind {
87 %xor = xor i32 %not, %y
90 ; CHECK-LABEL: @test9(
91 ; CHECK-NEXT: %y.not = xor i32 %y, -1
92 ; CHECK-NEXT: %z = or i32 %y.not, %x
93 ; CHECK-NEXT: ret i32 %z
96 define i32 @test10(i32 %A, i32 %B) {
97 %xor1 = xor i32 %B, %A
99 %xor2 = xor i32 %not, %B
100 %or = or i32 %xor1, %xor2
102 ; CHECK-LABEL: @test10(
103 ; CHECK-NEXT: ret i32 -1
106 define i32 @test11(i32 %A, i32 %B) {
107 %xor1 = xor i32 %B, %A
108 %not = xor i32 %A, -1
109 %xor2 = xor i32 %not, %B
110 %or = or i32 %xor1, %xor2
112 ; CHECK-LABEL: @test11(
113 ; CHECK-NEXT: ret i32 -1
116 ; (x | y) & ((~x) ^ y) -> (x & y)
117 define i32 @test12(i32 %x, i32 %y) {
119 %neg = xor i32 %x, -1
120 %xor = xor i32 %neg, %y
121 %and = and i32 %or, %xor
123 ; CHECK-LABEL: @test12(
124 ; CHECK-NEXT: %and = and i32 %x, %y
125 ; CHECK-NEXT: ret i32 %and
128 ; ((~x) ^ y) & (x | y) -> (x & y)
129 define i32 @test13(i32 %x, i32 %y) {
130 %neg = xor i32 %x, -1
131 %xor = xor i32 %neg, %y
133 %and = and i32 %xor, %or
135 ; CHECK-LABEL: @test13(
136 ; CHECK-NEXT: %and = and i32 %x, %y
137 ; CHECK-NEXT: ret i32 %and
140 ; ((x | y) ^ (x ^ y)) -> (x & y)
141 define i32 @test15(i32 %x, i32 %y) {
146 ; CHECK-LABEL: @test15(
147 ; CHECK-NEXT: %1 = and i32 %y, %x
148 ; CHECK-NEXT: ret i32 %1
151 ; ((x | ~y) ^ (~x | y)) -> x ^ y
152 define i32 @test16(i32 %x, i32 %y) {
153 %noty = xor i32 %y, -1
154 %notx = xor i32 %x, -1
155 %or1 = or i32 %x, %noty
156 %or2 = or i32 %notx, %y
157 %xor = xor i32 %or1, %or2
159 ; CHECK-LABEL: @test16(
160 ; CHECK-NEXT: %xor = xor i32 %x, %y
161 ; CHECK-NEXT: ret i32 %xor
164 ; ((x & ~y) ^ (~x & y)) -> x ^ y
165 define i32 @test17(i32 %x, i32 %y) {
166 %noty = xor i32 %y, -1
167 %notx = xor i32 %x, -1
168 %and1 = and i32 %x, %noty
169 %and2 = and i32 %notx, %y
170 %xor = xor i32 %and1, %and2
172 ; CHECK-LABEL: @test17(
173 ; CHECK-NEXT: %xor = xor i32 %x, %y
174 ; CHECK-NEXT: ret i32 %xor
177 define i32 @test18(i32 %a, i32 %b) {
179 %and1 = and i32 %or, 1
180 %and2 = and i32 %b, -2
181 %xor = or i32 %and1, %and2