summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2017-09-20 21:18:17 +0000
committerCraig Topper <craig.topper@intel.com>2017-09-20 21:18:17 +0000
commit562bf99ee61dbc28901253590780981c45e38e72 (patch)
treea31aa230492206272ba474b5e350a46baad110f5 /llvm/lib/Transforms
parent9b593a69385034e11afb41e87b4d4752e88aff37 (diff)
downloadbcm5719-llvm-562bf99ee61dbc28901253590780981c45e38e72.tar.gz
bcm5719-llvm-562bf99ee61dbc28901253590780981c45e38e72.zip
[InstCombine] Handle (X & C2) < C1 --> (X & C2) == 0
We already did (X & C2) > C1 --> (X & C2) != 0, if any bit set in (X & C2) will produce a result greater than C1. But there is an equivalent inverse condition with <= C1 (which will be canonicalized to < C1+1) Differential Revision: https://reviews.llvm.org/D38065 llvm-svn: 313819
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 980519bcf9c..90b98dd71ae 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1715,12 +1715,19 @@ Instruction *InstCombiner::foldICmpAndConstConst(ICmpInst &Cmp,
}
// (X & C2) > C1 --> (X & C2) != 0, if any bit set in (X & C2) will produce a
- // result greater than C1.
- unsigned NumTZ = C2->countTrailingZeros();
- if (Cmp.getPredicate() == ICmpInst::ICMP_UGT && NumTZ < C2->getBitWidth() &&
- NumTZ >= C1->getActiveBits()) {
- Constant *Zero = Constant::getNullValue(And->getType());
- return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
+ // result greater than C1. Also handle (X & C2) < C1 --> (X & C2) == 0.
+ if (!C2->isNullValue()) {
+ unsigned NumTZ = C2->countTrailingZeros();
+ if (Cmp.getPredicate() == ICmpInst::ICMP_UGT &&
+ NumTZ >= C1->getActiveBits()) {
+ Constant *Zero = Constant::getNullValue(And->getType());
+ return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
+ }
+ if (Cmp.getPredicate() == ICmpInst::ICMP_ULT &&
+ NumTZ >= C1->ceilLogBase2()) {
+ Constant *Zero = Constant::getNullValue(And->getType());
+ return new ICmpInst(ICmpInst::ICMP_EQ, And, Zero);
+ }
}
return nullptr;
OpenPOWER on IntegriCloud