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

Ankur Garg ankur29.garg at samsung.com
Fri Aug 22 23:42:46 PDT 2014


Hi David,
Thank you for the comments.
I have made the changes as you suggested. Please review the updated revision.


Updated Transformation: 
(A ^ B) ^ ((A ^ C) & B) -> (C ^ (B | (A ^ C))

New Z3 Link: http://rise4fun.com/Z3/KmnV7

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 ^ C) & B) -> (C ^ (B | (A ^ C)))
+    if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
+        match(Op1I, m_And(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B))))
+      return BinaryOperator::CreateXor(C, Builder->CreateOr(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,28 @@
 ; 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
+}
+
+define i32 @test16(i32 %a, i32 %b, i32 %c) {
+; CHECK-LABEL: test16(
+; CHECK-NEXT: %1 = xor i32 %a, %c
+; CHECK-NEXT: %2 = or i32 %1, %b
+; CHECK-NEXT: %xor2 = xor i32 %2, %c
+; CHECK-NEXT: ret i32 %xor2
+ %xor1 = xor i32 %a, %b
+ %not = xor i32 %a, %c
+ %and = and i32 %not, %b
+ %xor2 = xor i32 %xor1, %and
+ ret i32 %xor2
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5002.12879.patch
Type: text/x-patch
Size: 1646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140823/66ed3db4/attachment.bin>


More information about the llvm-commits mailing list