Skip to content

Commit 969b72f

Browse files
committed
Add test to check we can instcombine after reassociate. NFC.
The pattern became optimized after b92412f. Differential Revision: https://reviews.llvm.org/D112258
1 parent 439fc09 commit 969b72f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -O1 -S < %s | FileCheck %s
3+
4+
; Make sure we reassociate and1 with and2 before instcombine to allow
5+
; Demorgan logic fold:
6+
; (a & ~b) & ~c --> a & ~(b | c)
7+
define i4 @not_reassociate_and_and_not(i4 %a, i4 %b, i4 %c, i4 %d) {
8+
; CHECK-LABEL: @not_reassociate_and_and_not(
9+
; CHECK-NEXT: [[TMP1:%.*]] = or i4 [[B:%.*]], [[C:%.*]]
10+
; CHECK-NEXT: [[TMP2:%.*]] = xor i4 [[TMP1]], -1
11+
; CHECK-NEXT: [[AND2:%.*]] = and i4 [[TMP2]], [[A:%.*]]
12+
; CHECK-NEXT: [[AND3:%.*]] = and i4 [[AND2]], [[D:%.*]]
13+
; CHECK-NEXT: ret i4 [[AND3]]
14+
;
15+
%notb = xor i4 %b, -1
16+
%notc = xor i4 %c, -1
17+
%and1 = and i4 %a, %notb
18+
%and2 = and i4 %and1, %d
19+
%and3 = and i4 %and2, %notc
20+
ret i4 %and3
21+
}
22+
23+
; (a | ~b) | ~c --> a | ~(b & c)
24+
define i32 @not_reassociate_or_or_not(i32 %a, i32 %b, i32 %c, i32 %d) {
25+
; CHECK-LABEL: @not_reassociate_or_or_not(
26+
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[B:%.*]], [[C:%.*]]
27+
; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], -1
28+
; CHECK-NEXT: [[B2:%.*]] = or i32 [[TMP2]], [[A:%.*]]
29+
; CHECK-NEXT: [[B3:%.*]] = or i32 [[B2]], [[D:%.*]]
30+
; CHECK-NEXT: ret i32 [[B3]]
31+
;
32+
%notb = xor i32 %b, -1
33+
%notc = xor i32 %c, -1
34+
%b1 = or i32 %a, %notb
35+
%b2 = or i32 %b1, %d
36+
%b3 = or i32 %b2, %notc
37+
ret i32 %b3
38+
}

0 commit comments

Comments
 (0)