aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e186431..9b29d64 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -8553,7 +8553,20 @@ static void setLimitsForBinOp(const BinaryOperator &BO, APInt &Lower,
Lower = *C;
Upper = C->shl(ShiftAmount) + 1;
}
+ } else {
+ // If lowbit is set, value can never be zero.
+ if ((*C)[0])
+ Lower = APInt::getOneBitSet(Width, 0);
+ // If we are shifting a constant the largest it can be is if the longest
+ // sequence of consecutive ones is shifted to the highbits (breaking
+ // ties for which sequence is higher). At the moment we take a liberal
+ // upper bound on this by just popcounting the constant.
+ // TODO: There may be a bitwise trick for it longest/highest
+ // consecutative sequence of ones (naive method is O(Width) loop).
+ Upper = APInt::getHighBitsSet(Width, C->popcount()) + 1;
}
+ } else if (match(BO.getOperand(1), m_APInt(C)) && C->ult(Width)) {
+ Upper = APInt::getBitsSetFrom(Width, C->getZExtValue()) + 1;
}
break;