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

sonam kumari sonam.kumari at samsung.com
Thu Aug 21 02:18:56 PDT 2014


Hi majnemer, dexonsmith, rafael, suyog, silvas, nicholas,

Hi All,

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

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

Please help in reviewing the same.

David,

I tried to generalize the expression for " ( ~ A ) "  by using  " (A ^ C) " as you mentioned in few of my previous patches. But by doing that, I found the following result.

( ( A ^ B ) ^ ( (  A ^ C  ) | B ) ->  ( ( A & B) | ( ( ~B ) & C ) )

So, I think by doing this we are not reducing the number of operations. Am I thinking in the right direction.

Your inputs are highly welcomed. :)

Thanks,
Sonam.

http://reviews.llvm.org/D5001

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,16 @@
 ; CHECK-NEXT: %1 = and i32 %a, %b
 ; CHECK-NEXT: %xor = xor i32 %1, -1
 }
+
+; (A ^ B) ^ ((~A) | B) = (A | (~B))
+define i32 @test15(i32 %a, i32 %b) {
+; CHECK-LABEL: test15(
+; CHECK-NEXT: %1 = xor i32 %b, -1
+; CHECK-NEXT: %xor1 = or i32 %a, %1
+; CHECK-NEXT: ret i32 %xor1
+ %xor = xor i32 %a, %b
+ %not = xor i32 %a, -1
+ %or = or i32 %not, %b
+ %xor1 = xor i32 %xor, %or
+ ret i32 %xor1
+}
Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2651,6 +2651,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) | B) -> (A | (~B))
+    if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
+        match(Op1I, m_Or(m_Not(m_Specific(A)), m_Specific(B))))
+      return BinaryOperator::CreateOr(A, Builder->CreateNot(B));
   }
 
   // (A | B)^(~A) -> (A | ~B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5001.12751.patch
Type: text/x-patch
Size: 1294 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140821/e30b6740/attachment.bin>


More information about the llvm-commits mailing list