[llvm] 59d7f99 - [InstCombine] Precommit updated and-xor-or.ll tests. NFC.

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 1 13:29:41 PDT 2021


Author: Stanislav Mekhanoshin
Date: 2021-11-01T13:26:17-07:00
New Revision: 59d7f99148cbb022d21efaed7c53a21bf514a858

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

LOG: [InstCombine] Precommit updated 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 12e161c01957..a565991825d5 100644
--- a/llvm/test/Transforms/InstCombine/and-xor-or.ll
+++ b/llvm/test/Transforms/InstCombine/and-xor-or.ll
@@ -1336,3 +1336,273 @@ define i32 @or_and_not_not_wrong_b(i32 %a, i32 %b, i32 %c, i32 %d) {
   %or3 = or i32 %and, %not1
   ret i32 %or3
 }
+
+; (a & ~(b | c)) | ~(a | (b ^ c)) --> (~a & b & c) | ~(b | c)
+
+define i32 @and_not_or_or_not_or_xor(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_commute1(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_commute1(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[C:%.*]], [[B:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %c, %b
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_commute2(i32 %a0, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_commute2(
+; CHECK-NEXT:    [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[A]], [[NOT1]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %a, %not1
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_commute3(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_commute3(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[C]], [[B]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %c, %b
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_commute4(i32 %a0, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_commute4(
+; CHECK-NEXT:    [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[A]], [[NOT1]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[A]], [[XOR1]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %a, %not1
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %a, %xor1
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_commute5(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_commute5(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %not2, %and1
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_use1(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_use1(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[OR1]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  call void @use(i32 %or1)
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_use2(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_use2(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[NOT1]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  call void @use(i32 %not1)
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_use3(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_use3(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[AND1]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  call void @use(i32 %and1)
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_use4(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_use4(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[XOR1]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  call void @use(i32 %xor1)
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_use5(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_use5(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[OR2]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  call void @use(i32 %or2)
+  ret i32 %or3
+}
+
+define i32 @and_not_or_or_not_or_xor_use6(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @and_not_or_or_not_or_xor_use6(
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[B:%.*]], [[C:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[OR1]], -1
+; CHECK-NEXT:    [[AND1:%.*]] = and i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[B]], [[C]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[XOR1]], [[A]]
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[OR2]], -1
+; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[AND1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[NOT2]])
+; CHECK-NEXT:    ret i32 [[OR3]]
+;
+  %or1 = or i32 %b, %c
+  %not1 = xor i32 %or1, -1
+  %and1 = and i32 %not1, %a
+  %xor1 = xor i32 %b, %c
+  %or2 = or i32 %xor1, %a
+  %not2 = xor i32 %or2, -1
+  %or3 = or i32 %and1, %not2
+  call void @use(i32 %not2)
+  ret i32 %or3
+}


        


More information about the llvm-commits mailing list