[llvm] c0d6e1b - [InstCombine] Precommit new and-xor-or.ll tests. NFC.

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 21 15:17:00 PDT 2021


Author: Stanislav Mekhanoshin
Date: 2021-10-21T15:15:54-07:00
New Revision: c0d6e1b9e0b1c5426e77ef31f076850b87dee08b

URL: https://github.com/llvm/llvm-project/commit/c0d6e1b9e0b1c5426e77ef31f076850b87dee08b
DIFF: https://github.com/llvm/llvm-project/commit/c0d6e1b9e0b1c5426e77ef31f076850b87dee08b.diff

LOG: [InstCombine] Precommit new and-xor-or.ll tests. NFC.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/and-xor-or.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/and-xor-or.ll b/llvm/test/Transforms/InstCombine/and-xor-or.ll
index c206c546e908..6ed36ac9c800 100644
--- a/llvm/test/Transforms/InstCombine/and-xor-or.ll
+++ b/llvm/test/Transforms/InstCombine/and-xor-or.ll
@@ -698,3 +698,227 @@ define i32 @not_or_or_not_extra_or1_use(i32 %a0, i32 %b, i32 %c) {
   call void @use(i32 %or1)
   ret i32 %or2
 }
+
+; (c & ~(a | b)) | (b & ~(a | c)) --> ~a & (b ^ c)
+
+define i32 @or_not_and(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @or_not_and(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  ret i32 %or3
+}
+
+define i32 @or_not_and_commute1(i32 %a, i32 %b0, i32 %c) {
+; CHECK-LABEL: @or_not_and_commute1(
+; CHECK-NEXT:    [[B:%.*]] = sdiv i32 42, [[B0:%.*]]
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B]], [[A:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[B]], [[NOT2]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %b, %not2
+  %or3 = or i32 %and1, %and2
+  ret i32 %or3
+}
+
+define i32 @or_not_and_commute2(i32 %a, i32 %b0, i32 %c) {
+; CHECK-LABEL: @or_not_and_commute2(
+; CHECK-NEXT:    [[B:%.*]] = sdiv i32 42, [[B0:%.*]]
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B]], [[A:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[B]], [[NOT2]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND2]], [[AND1]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %b = sdiv i32 42, %b0 ; thwart complexity-based canonicalization
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %b, %not2
+  %or3 = or i32 %and2, %and1
+  ret i32 %or3
+}
+
+define i32 @or_not_and_commute3(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @or_not_and_commute3(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[C]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %a
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %c, %a
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  ret i32 %or3
+}
+
+define i32 @or_not_and_extra_not_use1(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @or_not_and_extra_not_use1(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    call void @use(i32 [[NOT1]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  call void @use(i32 %not1)
+  ret i32 %or3
+}
+
+define i32 @or_not_and_extra_not_use2(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @or_not_and_extra_not_use2(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    call void @use(i32 [[NOT2]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  call void @use(i32 %not2)
+  ret i32 %or3
+}
+
+define i32 @or_not_and_extra_and_use1(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @or_not_and_extra_and_use1(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    call void @use(i32 [[AND1]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  call void @use(i32 %and1)
+  ret i32 %or3
+}
+
+define i32 @or_not_and_extra_and_use2(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @or_not_and_extra_and_use2(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    call void @use(i32 [[AND2]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  call void @use(i32 %and2)
+  ret i32 %or3
+}
+
+define i32 @or_not_and_wrong_c(i32 %a, i32 %b, i32 %c, i32 %d) {
+; CHECK-LABEL: @or_not_and_wrong_c(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[D:%.*]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[B]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %d
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %b
+  %or3 = or i32 %and1, %and2
+  ret i32 %or3
+}
+
+define i32 @or_not_and_wrong_b(i32 %a, i32 %b, i32 %c, i32 %d) {
+; CHECK-LABEL: @or_not_and_wrong_b(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[C:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[C]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[AND2:%.*]] = and i32 [[NOT2]], [[D:%.*]]
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[AND2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %a, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %c
+  %or2 = or i32 %a, %c
+  %not2 = xor i32 %or2, -1
+  %and2 = and i32 %not2, %d
+  %or3 = or i32 %and1, %and2
+  ret i32 %or3
+}


        


More information about the llvm-commits mailing list