Skip to content

Commit

Permalink
[InstCombine] Precommit updated and-xor-or.ll tests. NFC.
Browse files Browse the repository at this point in the history
Tests for:

(~(a | b) & c) | ~(a | (b | c)) -> ~(a | b)
(~(a | b) & c) | ~(b | (a | c)) -> ~(a | b)
  • Loading branch information
rampitec committed Nov 4, 2021
1 parent 737e421 commit 5540e27
Showing 1 changed file with 181 additions and 0 deletions.
181 changes: 181 additions & 0 deletions llvm/test/Transforms/InstCombine/and-xor-or.ll
Expand Up @@ -2229,3 +2229,184 @@ define i32 @not_and_and_or_no_or_use8(i32 %a, i32 %b, i32 %c) {
call void @use(i32 %and2)
ret i32 %or2
}

; (~(a | b) & c) | ~(a | (b | c)) -> ~(a | b)
; (~(a | b) & c) | ~(b | (a | c)) -> ~(a | b)

define i32 @not_or_and_or_not_or_or(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or(
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[A:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: ret i32 [[OR4]]
;
%or1 = or i32 %b, %c
%or2 = or i32 %or1, %a
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_commute1(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or_commute1(
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A:%.*]], [[C:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[B:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: ret i32 [[OR4]]
;
%or1 = or i32 %a, %c
%or2 = or i32 %or1, %b
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_commute2(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or_commute2(
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[C:%.*]], [[B:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[A:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: ret i32 [[OR4]]
;
%or1 = or i32 %c, %b
%or2 = or i32 %or1, %a
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_commute3(i32 %a0, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or_commute3(
; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[A]], [[OR1]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[A]], [[B]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: ret i32 [[OR4]]
;
%a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
%or1 = or i32 %b, %c
%or2 = or i32 %a, %or1
%not1 = xor i32 %or2, -1
%or3 = or i32 %a, %b
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_commute4(i32 %a, i32 %b0, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or_commute4(
; CHECK-NEXT: [[B:%.*]] = sdiv i32 42, [[B0:%.*]]
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A:%.*]], [[C:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[B]], [[OR1]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: ret i32 [[OR4]]
;
%b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization
%or1 = or i32 %a, %c
%or2 = or i32 %b, %or1
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_commute5(i32 %a, i32 %b, i32 %c0) {
; CHECK-LABEL: @not_or_and_or_not_or_or_commute5(
; CHECK-NEXT: [[C:%.*]] = sdiv i32 42, [[C0:%.*]]
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[C]], [[A:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[B:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[C]], [[NOT2]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: ret i32 [[OR4]]
;
%c = sdiv i32 42, %c0 ; thwart complexity-based canonicalization
%or1 = or i32 %c, %a
%or2 = or i32 %or1, %b
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %c, %not2
%or4 = or i32 %and2, %not1
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_use1(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or_use1(
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[A:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: call void @use(i32 [[NOT1]])
; CHECK-NEXT: ret i32 [[OR4]]
;
%or1 = or i32 %b, %c
%or2 = or i32 %or1, %a
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
call void @use(i32 %not1)
ret i32 %or4
}

define i32 @not_or_and_or_not_or_or_use2(i32 %a, i32 %b, i32 %c) {
; CHECK-LABEL: @not_or_and_or_not_or_or_use2(
; CHECK-NEXT: [[OR1:%.*]] = or i32 [[A:%.*]], [[C:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[OR1]], [[B:%.*]]
; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[OR2]], -1
; CHECK-NEXT: [[OR3:%.*]] = or i32 [[B]], [[A]]
; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[OR3]], -1
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[NOT2]], [[C]]
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[AND2]], [[NOT1]]
; CHECK-NEXT: call void @use(i32 [[NOT1]])
; CHECK-NEXT: ret i32 [[OR4]]
;
%or1 = or i32 %a, %c
%or2 = or i32 %or1, %b
%not1 = xor i32 %or2, -1
%or3 = or i32 %b, %a
%not2 = xor i32 %or3, -1
%and2 = and i32 %not2, %c
%or4 = or i32 %and2, %not1
call void @use(i32 %not1)
ret i32 %or4
}

0 comments on commit 5540e27

Please sign in to comment.