[llvm] 6b560a8 - [InstCombine] add tests for DeMorgan with reassociation; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 21 07:44:40 PDT 2021


Author: Sanjay Patel
Date: 2021-10-21T10:39:28-04:00
New Revision: 6b560a8e235b4f610cce6a2db8188f42ce65c5fb

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

LOG: [InstCombine] add tests for DeMorgan with reassociation; NFC

These are direct mutations of the tests added for D112108 -
we should handle the sibling folds for 'or'.

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 3d93faf2f9d60..63bc69b6ac591 100644
--- a/llvm/test/Transforms/InstCombine/and-xor-or.ll
+++ b/llvm/test/Transforms/InstCombine/and-xor-or.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instcombine -S | FileCheck %s
 
+declare void @use(i32)
+
 ; a & (a ^ b) --> a & ~b
 
 define i32 @and_xor_common_op(i32 %pa, i32 %pb) {
@@ -569,7 +571,6 @@ define i32 @not_and_and_not_commute1(i32 %a, i32 %b, i32 %c) {
 
 ; ~c & (a & ~b) --> a & ~(b | c)
 
-declare void @use(i32)
 define i32 @not_and_and_not_commute2_extra_not_use(i32 %a0, i32 %b, i32 %c) {
 ; CHECK-LABEL: @not_and_and_not_commute2_extra_not_use(
 ; CHECK-NEXT:    [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
@@ -607,3 +608,96 @@ define i32 @not_and_and_not_extra_and1_use(i32 %a0, i32 %b, i32 %c) {
   call void @use(i32 %and1)
   ret i32 %and2
 }
+
+; (a | ~b) | ~c --> a | ~(b & c)
+
+define i32 @not_or_or_not(i32 %a0, i32 %b, i32 %c) {
+; CHECK-LABEL: @not_or_or_not(
+; CHECK-NEXT:    [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A]], [[NOT1]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR2]]
+;
+  %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
+  %not1 = xor i32 %b, -1
+  %not2 = xor i32 %c, -1
+  %or1 = or i32 %a, %not1
+  %or2 = or i32 %or1, %not2
+  ret i32 %or2
+}
+
+define <2 x i6> @not_or_or_not_2i6(<2 x i6> %a0, <2 x i6> %b, <2 x i6> %c) {
+; CHECK-LABEL: @not_or_or_not_2i6(
+; CHECK-NEXT:    [[A:%.*]] = sdiv <2 x i6> <i6 3, i6 3>, [[A0:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor <2 x i6> [[B:%.*]], <i6 -1, i6 -1>
+; CHECK-NEXT:    [[NOT2:%.*]] = xor <2 x i6> [[C:%.*]], <i6 -1, i6 undef>
+; CHECK-NEXT:    [[OR1:%.*]] = or <2 x i6> [[A]], [[NOT1]]
+; CHECK-NEXT:    [[OR2:%.*]] = or <2 x i6> [[OR1]], [[NOT2]]
+; CHECK-NEXT:    ret <2 x i6> [[OR2]]
+;
+  %a = sdiv <2 x i6> <i6 3, i6 3>, %a0 ; thwart complexity-based canonicalization
+  %not1 = xor <2 x i6> %b, <i6 -1, i6 -1>
+  %not2 = xor <2 x i6> %c, <i6 -1, i6 undef>
+  %or1 = or <2 x i6> %a, %not1
+  %or2 = or <2 x i6> %or1, %not2
+  ret <2 x i6> %or2
+}
+
+; (~b | a) | ~c --> a | ~(b & c)
+
+define i32 @not_or_or_not_commute1(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: @not_or_or_not_commute1(
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[NOT1]], [[A:%.*]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
+; CHECK-NEXT:    ret i32 [[OR2]]
+;
+  %not1 = xor i32 %b, -1
+  %not2 = xor i32 %c, -1
+  %or1 = or i32 %not1, %a
+  %or2 = or i32 %or1, %not2
+  ret i32 %or2
+}
+
+; ~c | (a | ~b) --> a | ~(b & c)
+
+define i32 @not_or_or_not_commute2_extra_not_use(i32 %a0, i32 %b, i32 %c) {
+; CHECK-LABEL: @not_or_or_not_commute2_extra_not_use(
+; CHECK-NEXT:    [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A]], [[NOT1]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[NOT2]])
+; CHECK-NEXT:    ret i32 [[OR2]]
+;
+  %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
+  %not1 = xor i32 %b, -1
+  %not2 = xor i32 %c, -1
+  %or1 = or i32 %a, %not1
+  %or2 = or i32 %not2, %or1
+  call void @use(i32 %not2)
+  ret i32 %or2
+}
+
+define i32 @not_or_or_not_extra_or1_use(i32 %a0, i32 %b, i32 %c) {
+; CHECK-LABEL: @not_or_or_not_extra_or1_use(
+; CHECK-NEXT:    [[A:%.*]] = sdiv i32 42, [[A0:%.*]]
+; CHECK-NEXT:    [[NOT1:%.*]] = xor i32 [[B:%.*]], -1
+; CHECK-NEXT:    [[NOT2:%.*]] = xor i32 [[C:%.*]], -1
+; CHECK-NEXT:    [[OR1:%.*]] = or i32 [[A]], [[NOT1]]
+; CHECK-NEXT:    [[OR2:%.*]] = or i32 [[OR1]], [[NOT2]]
+; CHECK-NEXT:    call void @use(i32 [[OR1]])
+; CHECK-NEXT:    ret i32 [[OR2]]
+;
+  %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization
+  %not1 = xor i32 %b, -1
+  %not2 = xor i32 %c, -1
+  %or1 = or i32 %a, %not1
+  %or2 = or i32 %or1, %not2
+  call void @use(i32 %or1)
+  ret i32 %or2
+}


        


More information about the llvm-commits mailing list