[PATCH] InstCombine ((A | ~B) ^ (~A | B)) to A ^ B
Mayur Pandey
mayur.p at samsung.com
Wed Aug 13 07:26:50 PDT 2014
Hi majnemer,
Hi,
A patch in instcombine to transform ((A | ~B) ^ (~A | B)) -> A ^ B.
Please review the patch.
Proof
$ cat t.cvc
A, B : BITVECTOR(32);
QUERY BVXOR((A | ~B),(~A |B)) = BVXOR(A,B);
$ cvc3 t.cvc
Valid.
http://reviews.llvm.org/D4883
Files:
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/or-xor.ll
Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2508,6 +2508,34 @@
if ((A == C && B == D) || (A == D && B == C))
return BinaryOperator::CreateXor(A, B);
}
+ // (A | ~B) ^ (~A | B) -> A ^ B
+ // (A | ~B) ^ (B | ~A) -> A ^ B
+ if (match(Op0I, m_Or(m_Value(A), m_Not(m_Value(B)))) &&
+ (match(Op1I, m_Or(m_Not(m_Specific(A)), m_Specific(B))) ||
+ match(Op1I, m_Or(m_Specific(B), m_Not(m_Specific(A)))))) {
+ return BinaryOperator::CreateXor(A, B);
+ }
+ // (~B | A) ^ (~A | B) -> A ^ B
+ // (~B | A) ^ (B | ~A) -> A ^ B
+ if (match(Op0I, m_Or(m_Not(m_Value(B)), m_Value(A))) &&
+ (match(Op1I, m_Or(m_Not(m_Specific(A)), m_Specific(B))) ||
+ match(Op1I, m_Or(m_Specific(B), m_Not(m_Specific(A)))))) {
+ return BinaryOperator::CreateXor(A, B);
+ }
+ // (~A | B) ^ (A | ~B) -> A ^ B
+ // (~A | B) ^ (~B | A) -> A ^ B
+ if (match(Op0I, m_Or(m_Not(m_Value(A)), m_Value(B))) &&
+ (match(Op1I, m_Or(m_Specific(A), m_Not(m_Specific(B)))) ||
+ match(Op1I, m_Or(m_Not(m_Specific(B)), m_Specific(A))))) {
+ return BinaryOperator::CreateXor(A, B);
+ }
+ // (B | ~A) ^ (A | ~B) -> A ^ B
+ // (B | ~A) ^ (~B | A) -> A ^ B
+ if (match(Op0I, m_Or(m_Value(B), m_Not(m_Value(A)))) &&
+ (match(Op1I, m_Or(m_Specific(A), m_Not(m_Specific(B)))) ||
+ match(Op1I, m_Or(m_Not(m_Specific(B)), m_Specific(A))))) {
+ return BinaryOperator::CreateXor(A, B);
+ }
// (A ^ B)^(A | B) -> A & B
if (match(Op0I, m_Xor(m_Value(A), m_Value(B))) &&
match(Op1I, m_Or(m_Value(C), m_Value(D)))) {
Index: test/Transforms/InstCombine/or-xor.ll
===================================================================
--- test/Transforms/InstCombine/or-xor.ll
+++ test/Transforms/InstCombine/or-xor.ll
@@ -147,3 +147,16 @@
; CHECK-NEXT: %1 = and i32 %y, %x
; CHECK-NEXT: ret i32 %1
}
+
+; ((x | ~y) ^ (~x | y)) -> x ^ y
+define i32 @test16(i32 %x, i32 %y) {
+ %1 = xor i32 %y, -1
+ %2 = xor i32 %x, -1
+ %3 = or i32 %x, %1
+ %4 = or i32 %2, %y
+ %5 = xor i32 %3, %4
+ ret i32 %5
+; CHECK-LABEL: @test16(
+; CHECK-NEXT: %1 = xor i32 %x, %y
+; CHECK-NEXT: ret i32 %1
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4883.12446.patch
Type: text/x-patch
Size: 2386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140813/c53ca986/attachment.bin>
More information about the llvm-commits
mailing list