[llvm] r358163 - [ValueTracking] Change if-else chain into switch in computeKnownBitsFromAssume
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 06:02:20 PDT 2019
Author: s.desmalen
Date: Thu Apr 11 06:02:19 2019
New Revision: 358163
URL: http://llvm.org/viewvc/llvm-project?rev=358163&view=rev
Log:
[ValueTracking] Change if-else chain into switch in computeKnownBitsFromAssume
This is a follow-up patch to D60504 to further improve
performance issues in computeKnownBitsFromAssume.
The patch is NFC, but may improve compile-time performance
if the compiler isn't clever enough to do the optimization
itself.
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=358163&r1=358162&r2=358163&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Thu Apr 11 06:02:19 2019
@@ -625,7 +625,10 @@ static void computeKnownBitsFromAssume(c
CmpInst::Predicate Pred;
uint64_t C;
- if (Cmp->getPredicate() == ICmpInst::ICMP_EQ) {
+ switch (Cmp->getPredicate()) {
+ default:
+ break;
+ case ICmpInst::ICMP_EQ:
// assume(v = a)
if (match(Cmp, m_c_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -762,7 +765,8 @@ static void computeKnownBitsFromAssume(c
Known.Zero |= RHSKnown.One << C;
Known.One |= RHSKnown.Zero << C;
}
- } else if (Cmp->getPredicate() == ICmpInst::ICMP_SGE) {
+ break;
+ case ICmpInst::ICMP_SGE:
// assume(v >=_s c) where c is non-negative
if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -774,7 +778,8 @@ static void computeKnownBitsFromAssume(c
Known.makeNonNegative();
}
}
- } else if (Cmp->getPredicate() == ICmpInst::ICMP_SGT) {
+ break;
+ case ICmpInst::ICMP_SGT:
// assume(v >_s c) where c is at least -1.
if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -786,7 +791,8 @@ static void computeKnownBitsFromAssume(c
Known.makeNonNegative();
}
}
- } else if (Cmp->getPredicate() == ICmpInst::ICMP_SLE) {
+ break;
+ case ICmpInst::ICMP_SLE:
// assume(v <=_s c) where c is negative
if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -798,7 +804,8 @@ static void computeKnownBitsFromAssume(c
Known.makeNegative();
}
}
- } else if (Cmp->getPredicate() == ICmpInst::ICMP_SLT) {
+ break;
+ case ICmpInst::ICMP_SLT:
// assume(v <_s c) where c is non-positive
if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
@@ -810,8 +817,9 @@ static void computeKnownBitsFromAssume(c
Known.makeNegative();
}
}
- // assume(v <=_u c)
- } else if (Cmp->getPredicate() == ICmpInst::ICMP_ULE) {
+ break;
+ case ICmpInst::ICMP_ULE:
+ // assume(v <=_u c)
if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
KnownBits RHSKnown(BitWidth);
@@ -820,8 +828,9 @@ static void computeKnownBitsFromAssume(c
// Whatever high bits in c are zero are known to be zero.
Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros());
}
+ break;
+ case ICmpInst::ICMP_ULT:
// assume(v <_u c)
- } else if (Cmp->getPredicate() == ICmpInst::ICMP_ULT) {
if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A))) &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
KnownBits RHSKnown(BitWidth);
@@ -842,6 +851,7 @@ static void computeKnownBitsFromAssume(c
else
Known.Zero.setHighBits(RHSKnown.countMinLeadingZeros());
}
+ break;
}
}
More information about the llvm-commits
mailing list