[PATCH] Added InstCombine transform for pattern "(A ^ B) | ((~A) ^ B) -> True".
sonam kumari
sonam.kumari at samsung.com
Sun Jul 27 23:42:45 PDT 2014
Hi nicholas, rafael, silvas, dexonsmith,
This patch implements transform for pattern "(A ^ B) | ((~A) ^ B) -> True".
Please help in reviewing the same.
Thanks,
Sonam.
http://reviews.llvm.org/D4691
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
@@ -1279,7 +1279,8 @@
return BinaryOperator::CreateAnd(A, Op1);
if (match(Op1, m_Or(m_Not(m_Specific(Op0)), m_Value(A))) ||
match(Op1, m_Or(m_Value(A), m_Not(m_Specific(Op0)))))
- return BinaryOperator::CreateAnd(A, Op0);
+ return BinaryOperator::CreateAnd(A, Op0);
+
}
if (ICmpInst *RHS = dyn_cast<ICmpInst>(Op1))
@@ -1982,6 +1983,11 @@
return BinaryOperator::CreateXor(NOr, C1);
}
+ // (A^B) | (~(A)^B) -> 1
+ if(match(Op0,m_Xor(m_Value(A),m_Value(B)))
+ && match(Op1,m_Xor(m_Not(m_Specific(A)),m_Specific(B))))
+ return BinaryOperator::CreateOr(A, Builder->CreateNot(A));
+
// (A & C)|(B & D)
Value *C = nullptr, *D = nullptr;
if (match(Op0, m_And(m_Value(A), m_Value(C))) &&
Index: test/Transforms/InstCombine/or.ll
===================================================================
--- test/Transforms/InstCombine/or.ll
+++ test/Transforms/InstCombine/or.ll
@@ -408,3 +408,13 @@
%or = or i32 %x, %sext
ret i32 %or
}
+
+define i32 @test39(i32%x,i32%y){
+; CHECK-LABEL: @test39(
+; CHECK-NEXT: ret i32 -1
+%xor = xor i32%x,%y
+%nega = xor i32%x,-1
+%xor1 = xor i32%nega,%y
+%or = or i32%xor,%xor1
+ret i32 %or
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4691.11938.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/340f3743/attachment.bin>
More information about the llvm-commits
mailing list