[PATCH] Added InstCombine transform for pattern "(A & B) ^ (A ^ B) -> (A | B)"
suyog
suyog.sarda at samsung.com
Tue Jul 22 06:22:10 PDT 2014
Hi dexonsmith, nicholas, rafael,
This patch implements transform for pattern "(A & B) ^ (A ^ B) -> (A | B)"
Please help in reviewing the same.
Thanks,
Suyog
http://reviews.llvm.org/D4618
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
@@ -2444,6 +2444,14 @@
if ((A == C && B == D) || (A == D && B == C))
return BinaryOperator::CreateXor(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))))
+ 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_And(m_Specific(A), m_Specific(B))))
+ return BinaryOperator::CreateOr(A, B);
}
// (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
Index: test/Transforms/InstCombine/xor2.ll
===================================================================
--- test/Transforms/InstCombine/xor2.ll
+++ test/Transforms/InstCombine/xor2.ll
@@ -82,3 +82,23 @@
; CHECK: lshr i32 %x, 16
; CHECK: ret
}
+
+; (A & B) ^ (A ^ B) -> (A | B)
+define i32 @test9(i32 %b, i32 %c) {
+ %and = and i32 %b, %c
+ %xor = xor i32 %b, %c
+ %xor2 = xor i32 %and, %xor
+ ret i32 %xor2
+; CHECK-LABEL: @test9(
+; CHECK-NEXT: %xor2 = or i32 %b, %c
+}
+
+; (A ^ B) ^ (A & B) -> (A | B)
+define i32 @test10(i32 %b, i32 %c) {
+ %xor = xor i32 %b, %c
+ %and = and i32 %b, %c
+ %xor2 = xor i32 %xor, %and
+ ret i32 %xor2
+; CHECK-LABEL: @test10(
+; CHECK-NEXT: %xor2 = or i32 %b, %c
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4618.11744.patch
Type: text/x-patch
Size: 1539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140722/1af5e78e/attachment.bin>
More information about the llvm-commits
mailing list