1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -reassociate -gvn -bdce -S | FileCheck %s
4 ; (~(a | b) & c) | ~(a | (b | c)) -> ~(a | b)
5 ; (~(a | b) & c) | ~(b | (a | c)) -> ~(a | b)
7 define i32 @not_or_and_or_not_or_or(i32 %a, i32 %b, i32 %c) {
8 ; CHECK-LABEL: @not_or_and_or_not_or_or(
9 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
10 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
11 ; CHECK-NEXT: ret i32 [[NOT2]]
14 %or2 = or i32 %or1, %a
15 %not1 = xor i32 %or2, -1
17 %not2 = xor i32 %or3, -1
18 %and2 = and i32 %not2, %c
19 %or4 = or i32 %and2, %not1
23 define i32 @not_or_and_or_not_or_or_commute1(i32 %a, i32 %b, i32 %c) {
24 ; CHECK-LABEL: @not_or_and_or_not_or_or_commute1(
25 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
26 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
27 ; CHECK-NEXT: ret i32 [[NOT2]]
30 %or2 = or i32 %or1, %b
31 %not1 = xor i32 %or2, -1
33 %not2 = xor i32 %or3, -1
34 %and2 = and i32 %not2, %c
35 %or4 = or i32 %and2, %not1
39 define i32 @not_or_and_or_not_or_or_commute2(i32 %a, i32 %b, i32 %c) {
40 ; CHECK-LABEL: @not_or_and_or_not_or_or_commute2(
41 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
42 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
43 ; CHECK-NEXT: ret i32 [[NOT2]]
46 %or2 = or i32 %or1, %a
47 %not1 = xor i32 %or2, -1
49 %not2 = xor i32 %or3, -1
50 %and2 = and i32 %not2, %c
51 %or4 = or i32 %and2, %not1
55 define i32 @not_or_and_or_not_or_or_commute3(i32 %a0, i32 %b, i32 %c) {
56 ; CHECK-LABEL: @not_or_and_or_not_or_or_commute3(
57 ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
58 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A]], [[B:%.*]]
59 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
60 ; CHECK-NEXT: ret i32 [[NOT2]]
62 %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
64 %or2 = or i32 %a, %or1
65 %not1 = xor i32 %or2, -1
67 %not2 = xor i32 %or3, -1
68 %and2 = and i32 %not2, %c
69 %or4 = or i32 %and2, %not1
73 define i32 @not_or_and_or_not_or_or_commute4(i32 %a, i32 %b0, i32 %c) {
74 ; CHECK-LABEL: @not_or_and_or_not_or_or_commute4(
75 ; CHECK-NEXT: [[B:%.*]] = sdiv i32 42, [[B0:%.*]]
76 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B]], [[A:%.*]]
77 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
78 ; CHECK-NEXT: ret i32 [[NOT2]]
80 %b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization
82 %or2 = or i32 %b, %or1
83 %not1 = xor i32 %or2, -1
85 %not2 = xor i32 %or3, -1
86 %and2 = and i32 %not2, %c
87 %or4 = or i32 %and2, %not1
91 define i32 @not_or_and_or_not_or_or_commute5(i32 %a, i32 %b, i32 %c0) {
92 ; CHECK-LABEL: @not_or_and_or_not_or_or_commute5(
93 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
94 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
95 ; CHECK-NEXT: ret i32 [[NOT2]]
97 %c = sdiv i32 42, %c0 ; thwart complexity-based canonicalization
99 %or2 = or i32 %or1, %b
100 %not1 = xor i32 %or2, -1
102 %not2 = xor i32 %or3, -1
103 %and2 = and i32 %c, %not2
104 %or4 = or i32 %and2, %not1
108 define i32 @not_or_and_or_not_or_or_use1(i32 %a, i32 %b, i32 %c) {
109 ; CHECK-LABEL: @not_or_and_or_not_or_or_use1(
110 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
111 ; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[C:%.*]]
112 ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
113 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
114 ; CHECK-NEXT: call void @use(i32 [[NOT1]])
115 ; CHECK-NEXT: ret i32 [[NOT2]]
118 %or2 = or i32 %or1, %a
119 %not1 = xor i32 %or2, -1
121 %not2 = xor i32 %or3, -1
122 %and2 = and i32 %not2, %c
123 %or4 = or i32 %and2, %not1
124 call void @use(i32 %not1)
128 define i32 @not_or_and_or_not_or_or_use2(i32 %a, i32 %b, i32 %c) {
129 ; CHECK-LABEL: @not_or_and_or_not_or_or_use2(
130 ; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
131 ; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[C:%.*]]
132 ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
133 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR1]], -1
134 ; CHECK-NEXT: call void @use(i32 [[NOT1]])
135 ; CHECK-NEXT: ret i32 [[NOT2]]
138 %or2 = or i32 %or1, %b
139 %not1 = xor i32 %or2, -1
141 %not2 = xor i32 %or3, -1
142 %and2 = and i32 %not2, %c
143 %or4 = or i32 %and2, %not1
144 call void @use(i32 %not1)
148 ; (~(a & b) | c) & ~(a & (b & c)) -> ~(a & b)
149 ; (~(a & b) | c) & ~(b & (a & c)) -> ~(a & b)
151 define i32 @not_and_or_and_not_and_and(i32 %a, i32 %b, i32 %c) {
152 ; CHECK-LABEL: @not_and_or_and_not_and_and(
153 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]
154 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
155 ; CHECK-NEXT: ret i32 [[NOT2]]
157 %and1 = and i32 %b, %c
158 %and2 = and i32 %and1, %a
159 %not1 = xor i32 %and2, -1
160 %and3 = and i32 %b, %a
161 %not2 = xor i32 %and3, -1
162 %or2 = or i32 %not2, %c
163 %and4 = and i32 %or2, %not1
167 define i32 @not_and_or_and_not_and_and_commute1(i32 %a, i32 %b, i32 %c) {
168 ; CHECK-LABEL: @not_and_or_and_not_and_and_commute1(
169 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]
170 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
171 ; CHECK-NEXT: ret i32 [[NOT2]]
173 %and1 = and i32 %a, %c
174 %and2 = and i32 %and1, %b
175 %not1 = xor i32 %and2, -1
176 %and3 = and i32 %b, %a
177 %not2 = xor i32 %and3, -1
178 %or2 = or i32 %not2, %c
179 %and4 = and i32 %or2, %not1
183 define i32 @not_and_or_and_not_and_and_commute2(i32 %a, i32 %b, i32 %c) {
184 ; CHECK-LABEL: @not_and_or_and_not_and_and_commute2(
185 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]
186 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
187 ; CHECK-NEXT: ret i32 [[NOT2]]
189 %and1 = and i32 %c, %b
190 %and2 = and i32 %and1, %a
191 %not1 = xor i32 %and2, -1
192 %and3 = and i32 %b, %a
193 %not2 = xor i32 %and3, -1
194 %or2 = or i32 %not2, %c
195 %and4 = and i32 %or2, %not1
199 define i32 @not_and_or_and_not_and_and_commute3(i32 %a0, i32 %b, i32 %c) {
200 ; CHECK-LABEL: @not_and_or_and_not_and_and_commute3(
201 ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
202 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[B:%.*]]
203 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
204 ; CHECK-NEXT: ret i32 [[NOT2]]
206 %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
207 %and1 = and i32 %b, %c
208 %and2 = and i32 %a, %and1
209 %not1 = xor i32 %and2, -1
210 %and3 = and i32 %a, %b
211 %not2 = xor i32 %and3, -1
212 %or2 = or i32 %not2, %c
213 %and4 = and i32 %or2, %not1
217 define i32 @not_and_or_and_not_and_and_commute4(i32 %a, i32 %b0, i32 %c) {
218 ; CHECK-LABEL: @not_and_or_and_not_and_and_commute4(
219 ; CHECK-NEXT: [[B:%.*]] = sdiv i32 42, [[B0:%.*]]
220 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B]], [[A:%.*]]
221 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
222 ; CHECK-NEXT: ret i32 [[NOT2]]
224 %b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization
225 %and1 = and i32 %a, %c
226 %and2 = and i32 %b, %and1
227 %not1 = xor i32 %and2, -1
228 %and3 = and i32 %b, %a
229 %not2 = xor i32 %and3, -1
230 %or2 = or i32 %not2, %c
231 %and4 = and i32 %or2, %not1
235 define i32 @not_and_or_and_not_and_and_commute5(i32 %a, i32 %b, i32 %c0) {
236 ; CHECK-LABEL: @not_and_or_and_not_and_and_commute5(
237 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]
238 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
239 ; CHECK-NEXT: ret i32 [[NOT2]]
241 %c = sdiv i32 42, %c0 ; thwart complexity-based canonicalization
242 %and1 = and i32 %c, %a
243 %and2 = and i32 %and1, %b
244 %not1 = xor i32 %and2, -1
245 %and3 = and i32 %b, %a
246 %not2 = xor i32 %and3, -1
247 %or2 = or i32 %c, %not2
248 %and4 = and i32 %or2, %not1
252 define i32 @not_and_or_and_not_and_and_use1(i32 %a, i32 %b, i32 %c) {
253 ; CHECK-LABEL: @not_and_or_and_not_and_and_use1(
254 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]
255 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[C:%.*]]
256 ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[AND2]], -1
257 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
258 ; CHECK-NEXT: call void @use(i32 [[NOT1]])
259 ; CHECK-NEXT: ret i32 [[NOT2]]
261 %and1 = and i32 %b, %c
262 %and2 = and i32 %and1, %a
263 %not1 = xor i32 %and2, -1
264 %and3 = and i32 %b, %a
265 %not2 = xor i32 %and3, -1
266 %or2 = or i32 %not2, %c
267 %and4 = and i32 %or2, %not1
268 call void @use(i32 %not1)
272 define i32 @not_and_or_and_not_and_and_use2(i32 %a, i32 %b, i32 %c) {
273 ; CHECK-LABEL: @not_and_or_and_not_and_and_use2(
274 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[B:%.*]], [[A:%.*]]
275 ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[C:%.*]]
276 ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[AND2]], -1
277 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[AND1]], -1
278 ; CHECK-NEXT: call void @use(i32 [[NOT1]])
279 ; CHECK-NEXT: ret i32 [[NOT2]]
281 %and1 = and i32 %a, %c
282 %and2 = and i32 %and1, %b
283 %not1 = xor i32 %and2, -1
284 %and3 = and i32 %b, %a
285 %not2 = xor i32 %and3, -1
286 %or2 = or i32 %not2, %c
287 %and4 = and i32 %or2, %not1
288 call void @use(i32 %not1)
292 declare void @use(i32)