[PATCH] Added InstCombine transform for pattern "(A & ~B) ^ (~A) -> ~(A & B)"

suyog suyog.sarda at samsung.com
Thu Jul 24 04:57:22 PDT 2014


Hi dexonsmith, nicholas, rafael, silvas,

This patch implements transform for pattern "(A & ~B) ^ (~A) -> ~(A & B)"

Please help in reviewing the same.

Z3 link : http://www.rise4fun.com/Z3/ld95

Thanks,
Suyog

http://reviews.llvm.org/D4653

Files:
  lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  test/Transforms/InstCombine/xor2.ll

Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2470,6 +2470,11 @@
       match(Op1, m_Not(m_Specific(A))))
     return BinaryOperator::CreateOr(A, Builder->CreateNot(B));
 
+  // (A & ~B) ^ (~A) -> ~(A & B)
+  if (match(Op0, m_And(m_Value(A), m_Not(m_Value(B)))) &&
+      match(Op1, m_Not(m_Specific(A))))
+    return BinaryOperator::CreateNot(Builder->CreateAnd(A, B));
+
   // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
   if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
     if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))
Index: test/Transforms/InstCombine/xor2.ll
===================================================================
--- test/Transforms/InstCombine/xor2.ll
+++ test/Transforms/InstCombine/xor2.ll
@@ -125,3 +125,25 @@
 ; CHECK-LABEL: @test10(
 ; CHECK-NEXT: %xor2 = or i32 %b, %c
 }
+
+define i32 @test11(i32 %a, i32 %b) {
+  %negb = xor i32 %b, -1
+  %and = and i32 %a, %negb
+  %nega = xor i32 %a, -1
+  %xor = xor i32 %and, %nega
+  ret i32 %xor
+; CHECK-LABEL: @test11(
+; CHECK-NEXT: %1 = and i32 %a, %b
+; CHECK-NEXT: %xor = xor i32 %1, -1
+}
+
+define i32 @test12(i32 %a, i32 %b) {
+  %nega = xor i32 %a, -1
+  %negb = xor i32 %b, -1
+  %and = and i32 %a, %negb
+  %xor = xor i32 %nega, %and
+  ret i32 %xor
+; CHECK-LABEL: @test12(
+; CHECK-NEXT: %1 = and i32 %a, %b
+; CHECK-NEXT: %xor = xor i32 %1, -1
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4653.11836.patch
Type: text/x-patch
Size: 1549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140724/8de59990/attachment.bin>


More information about the llvm-commits mailing list