[PATCH] InstCombine ((x | ~y) ^ (~x ^ y)) to (x & ~y)
Mayur Pandey
mayur.p at samsung.com
Sat Aug 16 01:14:30 PDT 2014
Hi majnemer,
Hi David,
Another small patch in instcombine. Can you please review the patch.
Proof:
$ cat t.cvc
A, B : BITVECTOR(32);
QUERY BVXOR((A | ~B),BVXOR(~A,B)) = (A & ~B);
$ cvc3 t.cvc
Valid.
Thanks,
Mayur
http://reviews.llvm.org/D4940
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
@@ -2542,6 +2542,14 @@
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_Or(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Op1I, m_Xor(m_Not(m_Specific(A)), m_Specific(B))))
+ return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
+ // (B ^ ~A) ^ (~B | A) -> A & ~B
+ if (match(Op0I, m_Xor(m_Value(B), m_Not(m_Value(A)))) &&
+ match(Op1I, m_Or(m_Not(m_Specific(B)), m_Specific(A))))
+ return BinaryOperator::CreateAnd(A, Builder->CreateNot(B));
}
// (A | B)^(~A) -> (A | ~B)
Index: test/Transforms/InstCombine/or-xor.ll
===================================================================
--- test/Transforms/InstCombine/or-xor.ll
+++ test/Transforms/InstCombine/or-xor.ll
@@ -160,3 +160,17 @@
; CHECK-NEXT: %xor = xor i32 %x, %y
; CHECK-NEXT: ret i32 %xor
}
+
+; ((x | ~y) ^ (~x ^ y)) -> (x & ~y)
+define i32 @test18(i32 %x, i32 %y) {
+ %noty = xor i32 %y, -1
+ %or = or i32 %x, %noty
+ %notx = xor i32 %x, -1
+ %xor1 = xor i32 %notx, %y
+ %xor2 = xor i32 %or, %xor1
+ ret i32 %xor2
+; CHECK-LABEL: @test18(
+; CHECK-NEXT: %1 = xor i32 %y, -1
+; CHECK-NEXT: %xor2 = and i32 %x, %1
+; CHECK-NEXT: ret i32 %xor2
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4940.12581.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140816/9d733925/attachment.bin>
More information about the llvm-commits
mailing list