summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2013-04-12 17:25:07 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2013-04-12 17:25:07 +0000
commit1a08accbb7e5430b41045d67eec09367ee96495e (patch)
tree600122d3d9324bf0deba2ddd9fdd94d97635dd9d /llvm/lib/Transforms
parent2249e9cfa8d1ee57d3b9fc1094f6874072c1ae1d (diff)
downloadbcm5719-llvm-1a08accbb7e5430b41045d67eec09367ee96495e.tar.gz
bcm5719-llvm-1a08accbb7e5430b41045d67eec09367ee96495e.zip
Simplify (A & ~B) in icmp if A is a power of 2
The transform will execute like so: (A & ~B) == 0 --> (A & B) != 0 (A & ~B) != 0 --> (A & B) == 0 llvm-svn: 179386
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 4d5fa8776e9..4c252c03d08 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2669,6 +2669,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
}
{ Value *A, *B;
+ // Transform (A & ~B) == 0 --> (A & B) != 0
+ // and (A & ~B) != 0 --> (A & B) == 0
+ // if A is a power of 2.
+ if (match(Op0, m_And(m_Value(A), m_Not(m_Value(B)))) &&
+ match(Op1, m_Zero()) && isKnownToBeAPowerOfTwo(A) && I.isEquality())
+ return new ICmpInst(I.getInversePredicate(),
+ Builder->CreateAnd(A, B),
+ Op1);
+
// ~x < ~y --> y < x
// ~x < cst --> ~cst < x
if (match(Op0, m_Not(m_Value(A)))) {
OpenPOWER on IntegriCloud