[PATCH] Added InstCombine Transformation for (A^B)^((~A)&B) -> A&(~B)

Ankur Garg ankur29.garg at samsung.com
Thu Aug 21 02:33:56 PDT 2014


Hi dexonsmith, majnemer, rafael, nicholas,

Hi everyone,

This patch implements the transformation (A^B)^((~A)&B) -> A&(~B)

Please help in reviewing it.

Z3 Link: http://rise4fun.com/Z3/jegC

Thanks,
Ankur Garg

http://reviews.llvm.org/D5002

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
@@ -2552,6 +2552,10 @@
     if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
         match(Op1I, m_And(m_Specific(A), m_Specific(B))))
       return BinaryOperator::CreateOr(A, B);
+    // (A ^ B) ^ ((~A) & B) -> A & (~B)
+    if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
+        match(Op1I, m_And(m_Not(m_Specific(A)), m_Specific(B))))
+      return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
   }
 
   // (A | B)^(~A) -> (A | ~B)
Index: test/Transforms/InstCombine/xor2.ll
===================================================================
--- test/Transforms/InstCombine/xor2.ll
+++ test/Transforms/InstCombine/xor2.ll
@@ -167,3 +167,15 @@
 ; CHECK-NEXT: %1 = and i32 %a, %b
 ; CHECK-NEXT: %xor = xor i32 %1, -1
 }
+
+define i32 @test15(i32 %a, i32 %b) {
+; CHECK-LABEL: test15(
+; CHECK-NEXT: %1 = xor i32 %b, -1
+; CHECK-NEXT: %xor2 = and i32 %a, %1
+; CHECK-NEXT: ret i32 %xor2
+ %xor1 = xor i32 %a, %b
+ %not = xor i32 %a, -1
+ %and = and i32 %not, %b
+ %xor2 = xor i32 %xor1, %and
+ ret i32 %xor2
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5002.12752.patch
Type: text/x-patch
Size: 1263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140821/20b2cf68/attachment.bin>


More information about the llvm-commits mailing list