summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarthik Bhat <kv.bhat@samsung.com>2014-08-13 05:13:14 +0000
committerKarthik Bhat <kv.bhat@samsung.com>2014-08-13 05:13:14 +0000
commita4a4db91be63ae4bff75ca57164d0938400ab40f (patch)
treed57d7b5de5977e8203afa1be90c3d54099f2dc90
parentb216ca55af27835918cfa1448d30be307d87b374 (diff)
downloadbcm5719-llvm-a4a4db91be63ae4bff75ca57164d0938400ab40f.tar.gz
bcm5719-llvm-a4a4db91be63ae4bff75ca57164d0938400ab40f.zip
InstCombine: Combine (xor (or %a, %b) (xor %a, %b)) to (add %a, %b)
Correctness proof of the transform using CVC3- $ cat t.cvc A, B : BITVECTOR(32); QUERY BVXOR(A | B, BVXOR(A,B) ) = A & B; $ cvc3 t.cvc Valid. llvm-svn: 215524
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp12
-rw-r--r--llvm/test/Transforms/InstCombine/or-xor.ll11
2 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 971995694e9..b83d3c64150 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2508,6 +2508,18 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if ((A == C && B == D) || (A == D && B == C))
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)))) {
+ if ((A == C && B == D) || (A == D && B == C))
+ return BinaryOperator::CreateAnd(A, B);
+ }
+ // (A | B)^(A ^ B) -> A & B
+ if (match(Op0I, m_Or(m_Value(A), m_Value(B))) &&
+ match(Op1I, m_Xor(m_Value(C), m_Value(D)))) {
+ if ((A == C && B == D) || (A == D && B == C))
+ return BinaryOperator::CreateAnd(A, B);
+ }
// (A & B) ^ (A ^ B) -> (A | B)
if (match(Op0I, m_And(m_Value(A), m_Value(B))) &&
match(Op1I, m_Xor(m_Specific(A), m_Specific(B))))
diff --git a/llvm/test/Transforms/InstCombine/or-xor.ll b/llvm/test/Transforms/InstCombine/or-xor.ll
index 5c15c456f8d..6984c44d9a3 100644
--- a/llvm/test/Transforms/InstCombine/or-xor.ll
+++ b/llvm/test/Transforms/InstCombine/or-xor.ll
@@ -136,3 +136,14 @@ define i32 @test13(i32 %x, i32 %y) {
; CHECK-NEXT: %and = and i32 %x, %y
; CHECK-NEXT: ret i32 %and
}
+
+; ((x | y) ^ (x ^ y)) -> (x & y)
+define i32 @test15(i32 %x, i32 %y) {
+ %1 = xor i32 %y, %x
+ %2 = or i32 %y, %x
+ %3 = xor i32 %2, %1
+ ret i32 %3
+; CHECK-LABEL: @test15(
+; CHECK-NEXT: %1 = and i32 %y, %x
+; CHECK-NEXT: ret i32 %1
+}
OpenPOWER on IntegriCloud