Skip to content

Commit ae89841

Browse files
committed
[InstCombine] add tests for bitwise logic folds; NFC
1 parent e5df0a5 commit ae89841

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

llvm/test/Transforms/InstCombine/and-or.ll

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt < %s -instcombine -S | FileCheck %s
33

4-
define i32 @func1(i32 %a, i32 %b) {
5-
; CHECK-LABEL: @func1(
4+
; ((b | a) & C1) | (b & C2) -> (a & C1) | b iff C1 == ~C2
5+
6+
define i32 @or_and_not_constant_commute0(i32 %a, i32 %b) {
7+
; CHECK-LABEL: @or_and_not_constant_commute0(
68
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1
79
; CHECK-NEXT: [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
810
; CHECK-NEXT: ret i32 [[T3]]
@@ -14,8 +16,8 @@ define i32 @func1(i32 %a, i32 %b) {
1416
ret i32 %t3
1517
}
1618

17-
define i32 @func2(i32 %a, i32 %b) {
18-
; CHECK-LABEL: @func2(
19+
define i32 @or_and_not_constant_commute1(i32 %a, i32 %b) {
20+
; CHECK-LABEL: @or_and_not_constant_commute1(
1921
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1
2022
; CHECK-NEXT: [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
2123
; CHECK-NEXT: ret i32 [[T3]]
@@ -27,8 +29,8 @@ define i32 @func2(i32 %a, i32 %b) {
2729
ret i32 %t3
2830
}
2931

30-
define i32 @func3(i32 %a, i32 %b) {
31-
; CHECK-LABEL: @func3(
32+
define i32 @or_and_not_constant_commute2(i32 %a, i32 %b) {
33+
; CHECK-LABEL: @or_and_not_constant_commute2(
3234
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1
3335
; CHECK-NEXT: [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
3436
; CHECK-NEXT: ret i32 [[T3]]
@@ -40,8 +42,8 @@ define i32 @func3(i32 %a, i32 %b) {
4042
ret i32 %t3
4143
}
4244

43-
define i32 @func4(i32 %a, i32 %b) {
44-
; CHECK-LABEL: @func4(
45+
define i32 @or_and_not_constant_commute3(i32 %a, i32 %b) {
46+
; CHECK-LABEL: @or_and_not_constant_commute3(
4547
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1
4648
; CHECK-NEXT: [[T3:%.*]] = or i32 [[TMP1]], [[B:%.*]]
4749
; CHECK-NEXT: ret i32 [[T3]]
@@ -53,6 +55,21 @@ define i32 @func4(i32 %a, i32 %b) {
5355
ret i32 %t3
5456
}
5557

58+
define <2 x i7> @or_and_not_constant_commute0_splat(<2 x i7> %a, <2 x i7> %b) {
59+
; CHECK-LABEL: @or_and_not_constant_commute0_splat(
60+
; CHECK-NEXT: [[T:%.*]] = or <2 x i7> [[B:%.*]], [[A:%.*]]
61+
; CHECK-NEXT: [[T1:%.*]] = and <2 x i7> [[T]], <i7 42, i7 42>
62+
; CHECK-NEXT: [[T2:%.*]] = and <2 x i7> [[B]], <i7 -43, i7 -43>
63+
; CHECK-NEXT: [[T3:%.*]] = or <2 x i7> [[T1]], [[T2]]
64+
; CHECK-NEXT: ret <2 x i7> [[T3]]
65+
;
66+
%t = or <2 x i7> %b, %a
67+
%t1 = and <2 x i7> %t, <i7 42, i7 42>
68+
%t2 = and <2 x i7> %b, <i7 -43, i7 -43>
69+
%t3 = or <2 x i7> %t1, %t2
70+
ret <2 x i7> %t3
71+
}
72+
5673
; Check variants of:
5774
; and ({x}or X, Y), C --> {x}or X, (and Y, C)
5875
; ...in the following 5 tests.

llvm/test/Transforms/InstCombine/or-xor.ll

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,10 @@ define i32 @test15_commuted(i32 %x, i32 %y) {
273273
ret i32 %xor
274274
}
275275

276-
define i32 @test16(i32 %a, i32 %b) {
277-
; CHECK-LABEL: @test16(
276+
; ((a ^ b) & C1) | (b & C2) -> (a & C1) ^ b iff C1 == ~C2
277+
278+
define i32 @or_and_xor_not_constant_commute0(i32 %a, i32 %b) {
279+
; CHECK-LABEL: @or_and_xor_not_constant_commute0(
278280
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], 1
279281
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[TMP1]], [[B:%.*]]
280282
; CHECK-NEXT: ret i32 [[XOR]]
@@ -286,6 +288,49 @@ define i32 @test16(i32 %a, i32 %b) {
286288
ret i32 %xor
287289
}
288290

291+
define i9 @or_and_xor_not_constant_commute1(i9 %a, i9 %b) {
292+
; CHECK-LABEL: @or_and_xor_not_constant_commute1(
293+
; CHECK-NEXT: [[TMP1:%.*]] = and i9 [[A:%.*]], 42
294+
; CHECK-NEXT: [[XOR:%.*]] = xor i9 [[TMP1]], [[B:%.*]]
295+
; CHECK-NEXT: ret i9 [[XOR]]
296+
;
297+
%or = xor i9 %b, %a
298+
%and1 = and i9 %or, 42
299+
%and2 = and i9 %b, -43
300+
%xor = or i9 %and1, %and2
301+
ret i9 %xor
302+
}
303+
304+
define <2 x i9> @or_and_xor_not_constant_commute2_splat(<2 x i9> %a, <2 x i9> %b) {
305+
; CHECK-LABEL: @or_and_xor_not_constant_commute2_splat(
306+
; CHECK-NEXT: [[OR:%.*]] = xor <2 x i9> [[B:%.*]], [[A:%.*]]
307+
; CHECK-NEXT: [[AND1:%.*]] = and <2 x i9> [[OR]], <i9 42, i9 42>
308+
; CHECK-NEXT: [[AND2:%.*]] = and <2 x i9> [[B]], <i9 -43, i9 -43>
309+
; CHECK-NEXT: [[XOR:%.*]] = or <2 x i9> [[AND2]], [[AND1]]
310+
; CHECK-NEXT: ret <2 x i9> [[XOR]]
311+
;
312+
%or = xor <2 x i9> %b, %a
313+
%and1 = and <2 x i9> %or, <i9 42, i9 42>
314+
%and2 = and <2 x i9> %b, <i9 -43, i9 -43>
315+
%xor = or <2 x i9> %and2, %and1
316+
ret <2 x i9> %xor
317+
}
318+
319+
define <2 x i9> @or_and_xor_not_constant_commute3_splat(<2 x i9> %a, <2 x i9> %b) {
320+
; CHECK-LABEL: @or_and_xor_not_constant_commute3_splat(
321+
; CHECK-NEXT: [[OR:%.*]] = xor <2 x i9> [[A:%.*]], [[B:%.*]]
322+
; CHECK-NEXT: [[AND1:%.*]] = and <2 x i9> [[OR]], <i9 42, i9 42>
323+
; CHECK-NEXT: [[AND2:%.*]] = and <2 x i9> [[B]], <i9 -43, i9 -43>
324+
; CHECK-NEXT: [[XOR:%.*]] = or <2 x i9> [[AND2]], [[AND1]]
325+
; CHECK-NEXT: ret <2 x i9> [[XOR]]
326+
;
327+
%or = xor <2 x i9> %a, %b
328+
%and1 = and <2 x i9> %or, <i9 42, i9 42>
329+
%and2 = and <2 x i9> %b, <i9 -43, i9 -43>
330+
%xor = or <2 x i9> %and2, %and1
331+
ret <2 x i9> %xor
332+
}
333+
289334
define i8 @not_or(i8 %x) {
290335
; CHECK-LABEL: @not_or(
291336
; CHECK-NEXT: [[NOTX:%.*]] = xor i8 [[X:%.*]], -1

0 commit comments

Comments
 (0)