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

sonam kumari sonam.kumari at samsung.com
Sun Aug 24 21:16:59 PDT 2014


Hi David,

Thanks for your time and support. :)
I have modified the patch based on your review comments.
Kindly review it.Your comments are highly welcomed.

Regards,
Sonam.

http://reviews.llvm.org/D5001

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
@@ -2651,6 +2651,11 @@
     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) -> C ^ (B & (A ^ C))
+    if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
+        match(Op1I, m_Or(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B))))
+      return BinaryOperator::CreateXor(
+          C, Builder->CreateAnd(B, Builder->CreateXor(A, C)));
   }
 
   // (A | B)^(~A) -> (A | ~B)
Index: test/Transforms/InstCombine/xor2.ll
===================================================================
--- test/Transforms/InstCombine/xor2.ll
+++ test/Transforms/InstCombine/xor2.ll
@@ -167,3 +167,17 @@
 ; CHECK-NEXT: %1 = and i32 %a, %b
 ; CHECK-NEXT: %xor = xor i32 %1, -1
 }
+
+; (A ^ B) ^ ((A ^ C) | B) -> C ^ (B & (A ^ C))
+define i32 @test15(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: test15(
+; CHECK-NEXT: %1 = xor i32 %a, %c
+; CHECK-NEXT: %2 = and i32 %1, %b
+; CHECK-NEXT: %xor2 = xor i32 %2, %c
+; CHECK-NEXT: ret i32 %xor2
+ %xor = xor i32 %a, %b
+ %xor1 = xor i32 %a, %c
+ %or = or i32 %xor1, %b
+ %xor2 = xor i32 %xor, %or
+ ret i32 %xor2
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5001.12889.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140825/ed826cf5/attachment.bin>


More information about the llvm-commits mailing list