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

Ankur Garg ankur29.garg at samsung.com
Tue Aug 19 03:07:14 PDT 2014


Ran the clang-format on the code.

http://reviews.llvm.org/D4970

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
@@ -2528,6 +2528,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) -> ((~B) & C)
+    if (match(Op0I, m_Or(m_Value(A), m_Value(B))) &&
+        match(Op1I, m_Or(m_Xor(m_Specific(A), m_Value(C)), m_Specific(B))))
+      return BinaryOperator::CreateAnd(Builder->CreateNot(B), 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,16 @@
 ; CHECK-NEXT: %1 = and i32 %a, %b
 ; CHECK-NEXT: %xor = xor i32 %1, -1
 }
+
+define i32 @test15(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: @test15(
+; CHECK-NEXT: %1 = xor i32 %y, -1
+; CHECK-NEXT: %xor1 = and i32 %1, %z
+; CHECK-NEXT: ret i32 %xor1
+ %and = or i32 %x, %y
+ %xor = xor i32 %x, %z
+ %or = or i32 %xor, %y
+ %xor1 = xor i32 %and, %or
+ ret i32 %xor1
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4970.12650.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140819/d1545ec9/attachment.bin>


More information about the llvm-commits mailing list