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

sonam kumari sonam.kumari at samsung.com
Fri Aug 8 04:05:10 PDT 2014


Hi dexonsmith, nicholas, rafael, silvas, suyog,

This patch implements transform for pattern "(A ^ B) | ((~A) ^ B) -> True".

Please help in reviewing the same.

Thanks,
Sonam.

http://reviews.llvm.org/D4828

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

Index: test/Transforms/InstCombine/xor2.ll
===================================================================
--- test/Transforms/InstCombine/xor2.ll
+++ test/Transforms/InstCombine/xor2.ll
@@ -167,3 +167,14 @@
 ; CHECK-NEXT: %1 = and i32 %a, %b
 ; CHECK-NEXT: %xor = xor i32 %1, -1
 }
+
+define i32 @test15(i32 %x, i32 %y) {
+  %and = and i32 %x, %y
+  %nega = xor i32 %x, -1
+  %or = or i32 %nega, %y
+  %and1 = xor i32 %and, %or
+  ret i32 %and1
+; CHECK-LABEL: @test15(
+; CHECK-NEXT: %and1 = xor i32 %x, -1
+; CHECK-NEXT: ret i32 %and1
+}
Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2516,6 +2516,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 ^ C) | B) -> (~A)
+    if (match(Op0I, m_And(m_Value(A), m_Value(B))) &&
+        match(Op1I, m_Or(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B))))
+      return BinaryOperator::CreateNot(A);
   }
 
   // (A | B)^(~A) -> (A | ~B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4828.12302.patch
Type: text/x-patch
Size: 1218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140808/43028972/attachment.bin>


More information about the llvm-commits mailing list