[PATCH] Added InstCombine Transform for ((B | C) & A) | B -> B | (A & C)
sonam kumari
sonam.kumari at samsung.com
Tue Aug 12 22:28:46 PDT 2014
Hi David,
Thanks for your valuable comments.
I have changed the second "if" condition as you mentioned.
For handling ( ( B | C ) & A ) | C -> C | ( A & B) :
I passed the following test case using reassociate before instcombine
define i32 @test19(i32 %x, i32 %y, i32 %z) {
%or = or i32 %y, %z
%and = and i32 %x, %or
%or1 = or i32 %and, %z
ret i32 %or1
}
The output I got was :
define i32 @test19(i32 %x, i32 %y, i32 %z) {
%1 = and i32 %x, %y
%or1 = or i32 %1, %z
ret i32 %or1
}
So, I guess we need not handle this case.
Please help in reviewing the same.
Thanks,
Sonam.
http://reviews.llvm.org/D4865
Files:
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/or.ll
Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2124,6 +2124,11 @@
if (Op0->hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
return BinaryOperator::CreateOr(Op1, C);
+ // ((B | C) & A) | B -> B | (A & C)
+ if (match(Op0, m_And(m_Or(m_Value(B), m_Value(C)), m_Value(A))))
+ if (Op1 == B)
+ return BinaryOperator::CreateOr(B, Builder->CreateAnd(A, C));
+
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
if (BinaryOperator *SI1 = dyn_cast<BinaryOperator>(Op1)) {
if (BinaryOperator *SI0 = dyn_cast<BinaryOperator>(Op0))
Index: test/Transforms/InstCombine/or.ll
===================================================================
--- test/Transforms/InstCombine/or.ll
+++ test/Transforms/InstCombine/or.ll
@@ -469,3 +469,14 @@
%or = or i32 %xor, %and
ret i32 %or
}
+
+define i32 @test45(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: test45(
+; CHECK-NEXT: %1 = and i32 %x, %z
+; CHECK-NEXT: %or1 = or i32 %1, %y
+; CHECK-NEXT: ret i32 %or1
+ %or = or i32 %y, %z
+ %and = and i32 %x, %or
+ %or1 = or i32 %and, %y
+ ret i32 %or1
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4865.12432.patch
Type: text/x-patch
Size: 1275 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140813/89154ce5/attachment.bin>
More information about the llvm-commits
mailing list