summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-11-30 13:08:13 +0000
committerBill Wendling <isanbard@gmail.com>2008-11-30 13:08:13 +0000
commit9eef421e12c83a1783ff525ccb80d6799f2a495c (patch)
tree4f013a04f3c1c1cb5b4eb2437030bad1df19aad6 /llvm/lib
parent2fe322982475f900cc369ef245bb9de656cce286 (diff)
downloadbcm5719-llvm-9eef421e12c83a1783ff525ccb80d6799f2a495c.tar.gz
bcm5719-llvm-9eef421e12c83a1783ff525ccb80d6799f2a495c.zip
Implement (A&((~A)|B)) -> A&B transformation in the instruction combiner. This
takes care of all permutations of this pattern. llvm-svn: 60290
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/README.txt10
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp19
2 files changed, 19 insertions, 10 deletions
diff --git a/llvm/lib/Target/README.txt b/llvm/lib/Target/README.txt
index b0d93f0264a..bf7c0b14475 100644
--- a/llvm/lib/Target/README.txt
+++ b/llvm/lib/Target/README.txt
@@ -1086,16 +1086,6 @@ produces better code on X86.
//===---------------------------------------------------------------------===//
-From GCC Bug 33512:
-int f(int y, int x)
-{
- return x & ((~x) | y);
-}
-Should combine to x & y. Currently not optimized with "clang
--emit-llvm-bc | opt -std-compile-opts".
-
-//===---------------------------------------------------------------------===//
-
From GCC Bug 15784:
#define abs(x) x>0?x:-x
int f(int x, int y)
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 8716e9a8a6c..ace3ff80d4f 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3993,6 +3993,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
std::swap(Op0, Op1);
}
}
+
if (Op1->hasOneUse() &&
match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
if (B == Op0) { // B&(A^B) -> B&(B^A)
@@ -4005,6 +4006,24 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
return BinaryOperator::CreateAnd(A, NotB);
}
}
+
+ // (A&((~A)|B)) -> A&B
+ if (match(Op0, m_Or(m_Not(m_Value(A)), m_Value(B)))) {
+ if (A == Op1)
+ return BinaryOperator::CreateAnd(A, B);
+ }
+ if (match(Op0, m_Or(m_Value(A), m_Not(m_Value(B))))) {
+ if (B == Op1)
+ return BinaryOperator::CreateAnd(A, B);
+ }
+ if (match(Op1, m_Or(m_Not(m_Value(A)), m_Value(B)))) {
+ if (A == Op0)
+ return BinaryOperator::CreateAnd(A, B);
+ }
+ if (match(Op1, m_Or(m_Value(A), m_Not(m_Value(B))))) {
+ if (B == Op0)
+ return BinaryOperator::CreateAnd(A, B);
+ }
}
if (ICmpInst *RHS = dyn_cast<ICmpInst>(Op1)) {
OpenPOWER on IntegriCloud