[llvm-branch-commits] [llvm] 1fda233 - [NFC][InstCombine] Add test for `a & ~(a ^ b)` pattern

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Dec 24 10:27:30 PST 2020


Author: Roman Lebedev
Date: 2020-12-24T21:20:48+03:00
New Revision: 1fda23367d46955fcb6e605f4114d47e499f0901

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

LOG: [NFC][InstCombine] Add test for `a & ~(a ^ b)` pattern

... which is a variation of `a & (a ^ ~b)` --> a & b`.
A follow-up patch exposes this missing fold, so we need to fix it first.

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 6e54c5318d21..4a27e3f00c89 100644
--- a/llvm/test/Transforms/InstCombine/and-xor-or.ll
+++ b/llvm/test/Transforms/InstCombine/and-xor-or.ll
@@ -96,6 +96,53 @@ define i32 @and_xor_not_common_op(i32 %a, i32 %b) {
   ret i32 %t4
 }
 
+; a & (a ^ ~b) --> a & b
+
+define i32 @and_xor_not_common_op_extrause(i32 %a, i32 %b, i32* %dst) {
+; CHECK-LABEL: @and_xor_not_common_op_extrause(
+; CHECK-NEXT:    [[B2:%.*]] = xor i32 [[B:%.*]], -1
+; CHECK-NEXT:    store i32 [[B2]], i32* [[DST:%.*]], align 4
+; CHECK-NEXT:    [[T4:%.*]] = and i32 [[A:%.*]], [[B]]
+; CHECK-NEXT:    ret i32 [[T4]]
+;
+  %b2 = xor i32 %b, -1
+  store i32 %b2, i32* %dst
+  %t2 = xor i32 %a, %b2
+  %t4 = and i32 %t2, %a
+  ret i32 %t4
+}
+
+; a & ~(a ^ b) --> a & b
+
+define i32 @and_not_xor_common_op(i32 %a, i32 %b) {
+; CHECK-LABEL: @and_not_xor_common_op(
+; CHECK-NEXT:    [[B2:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = xor i32 [[B2]], -1
+; CHECK-NEXT:    [[T4:%.*]] = and i32 [[T2]], [[A]]
+; CHECK-NEXT:    ret i32 [[T4]]
+;
+  %b2 = xor i32 %b, %a
+  %t2 = xor i32 %b2, -1
+  %t4 = and i32 %t2, %a
+  ret i32 %t4
+}
+
+declare i32 @gen32()
+define i32 @and_not_xor_common_op_commutative(i32 %b) {
+; CHECK-LABEL: @and_not_xor_common_op_commutative(
+; CHECK-NEXT:    [[A:%.*]] = call i32 @gen32()
+; CHECK-NEXT:    [[B2:%.*]] = xor i32 [[A]], [[B:%.*]]
+; CHECK-NEXT:    [[T2:%.*]] = xor i32 [[B2]], -1
+; CHECK-NEXT:    [[T4:%.*]] = and i32 [[A]], [[T2]]
+; CHECK-NEXT:    ret i32 [[T4]]
+;
+  %a = call i32 @gen32()
+  %b2 = xor i32 %a, %b ; swapped order
+  %t2 = xor i32 %b2, -1
+  %t4 = and i32 %a, %t2 ; swapped order
+  ret i32 %t4
+}
+
 ; rdar://10770603
 ; (x & y) | (x ^ y) -> x | y
 


        


More information about the llvm-branch-commits mailing list