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

sonam kumari sonam.kumari at samsung.com
Sun Aug 10 23:15:31 PDT 2014


Hi David,Suyog,

Thanks David for pointing out the mistake.I have submitted the patch related to the expression you mentioned.

Thanks Suyog for this valuable information.I have attached the Z3 link for this expression.

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

Please help in reviewing the patch.

Regards,
Sonam.

http://reviews.llvm.org/D4828

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
@@ -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) -> (B | C) ^ 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::CreateXor(Builder->CreateOr(B, C), A);
   }
 
   // (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 %x, i32 %y, i32 %z) {
+  %and = and i32 %x, %y
+  %xor = xor i32 %x, %z
+  %or = or i32 %xor, %y
+  %xor1 = xor i32 %and, %or
+  ret i32 %xor1
+; CHECK-LABEL: @test15(
+; CHECK-NEXT: %1 = or i32 %y, %z
+; CHECK-NEXT: %xor1 = xor i32 %1, %x
+; CHECK-NEXT: ret i32 %xor1
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4828.12341.patch
Type: text/x-patch
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140811/534d180f/attachment.bin>


More information about the llvm-commits mailing list