[PATCH] Added InstCombine Transformation for (A|B)^((A^C)|B) --> (~B)C
Ankur Garg
ankur29.garg at samsung.com
Tue Aug 19 02:23:34 PDT 2014
Hi suyog, dexonsmith, majnemer, sonamkumari,
Hi everyone,
This patch implements the transformation (A|B)^((A^C)|B) --> (~B)C
Please help in reviewing it.
Z3 Link : http://rise4fun.com/Z3/XslkK
Thanks,
Ankur Garg
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,12 @@
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.12648.patch
Type: text/x-patch
Size: 1293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140819/68262d2e/attachment.bin>
More information about the llvm-commits
mailing list