[llvm] 0cc3e10 - [SCEV] Avoid range intersection idiom in getRangeForUnkownRecurrence [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 28 12:48:23 PDT 2021
Author: Philip Reames
Date: 2021-04-28T12:48:17-07:00
New Revision: 0cc3e10f5e291d85d5c5047ee783340a8694a249
URL: https://github.com/llvm/llvm-project/commit/0cc3e10f5e291d85d5c5047ee783340a8694a249
DIFF: https://github.com/llvm/llvm-project/commit/0cc3e10f5e291d85d5c5047ee783340a8694a249.diff
LOG: [SCEV] Avoid range intersection idiom in getRangeForUnkownRecurrence [NFC]
Addresses a review comment from D101181
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index c2bf309e0591..f224ab29d942 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5654,7 +5654,7 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
const DataLayout &DL = getDataLayout();
unsigned BitWidth = getTypeSizeInBits(U->getType());
- ConstantRange CR(BitWidth, /*isFullSet=*/true);
+ const ConstantRange FullSet(BitWidth, /*isFullSet=*/true);
// Match a simple recurrence of the form: <start, ShiftOp, Step>, and then
// use information about the trip count to improve our available range. Note
@@ -5666,19 +5666,19 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
// below intentionally handles the case where step is not loop invariant.
auto *P = dyn_cast<PHINode>(U->getValue());
if (!P)
- return CR;
+ return FullSet;
// Make sure that no Phi input comes from an unreachable block. Otherwise,
// even the values that are not available in these blocks may come from them,
// and this leads to false-positive recurrence test.
for (auto *Pred : predecessors(P->getParent()))
if (!DT.isReachableFromEntry(Pred))
- return CR;
+ return FullSet;
BinaryOperator *BO;
Value *Start, *Step;
if (!matchSimpleRecurrence(P, BO, Start, Step))
- return CR;
+ return FullSet;
// If we found a recurrence in reachable code, we must be in a loop. Note
// that BO might be in some subloop of L, and that's completely okay.
@@ -5690,12 +5690,12 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
// with malformed loop information during the midst of the transform.
// There doesn't appear to be an obvious fix, so for the moment bailout
// until the caller issue can be fixed. PR49566 tracks the bug.
- return CR;
+ return FullSet;
// TODO: Extend to other opcodes such as mul, and div
switch (BO->getOpcode()) {
default:
- return CR;
+ return FullSet;
case Instruction::AShr:
case Instruction::LShr:
case Instruction::Shl:
@@ -5704,11 +5704,11 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
if (BO->getOperand(0) != P)
// TODO: Handle the power function forms some day.
- return CR;
+ return FullSet;
unsigned TC = getSmallConstantMaxTripCount(L);
if (!TC || TC >= BitWidth)
- return CR;
+ return FullSet;
auto KnownStart = computeKnownBits(Start, DL, 0, &AC, nullptr, &DT);
auto KnownStep = computeKnownBits(Step, DL, 0, &AC, nullptr, &DT);
@@ -5721,7 +5721,7 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
bool Overflow = false;
auto TotalShift = MaxShiftAmt.umul_ov(TCAP, Overflow);
if (Overflow)
- return CR;
+ return FullSet;
switch (BO->getOpcode()) {
default:
@@ -5734,17 +5734,14 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
// Thus, the end value is closer to zero than the start.
auto KnownEnd = KnownBits::ashr(KnownStart,
KnownBits::makeConstant(TotalShift));
- if (KnownStart.isNonNegative()) {
+ if (KnownStart.isNonNegative())
// Analogous to lshr (simply not yet canonicalized)
- auto R = ConstantRange::getNonEmpty(KnownEnd.getMinValue(),
- KnownStart.getMaxValue() + 1);
- CR = CR.intersectWith(R);
- } else if (KnownStart.isNegative()) {
+ return ConstantRange::getNonEmpty(KnownEnd.getMinValue(),
+ KnownStart.getMaxValue() + 1);
+ if (KnownStart.isNegative())
// End >=u Start && End <=s Start
- auto R = ConstantRange::getNonEmpty(KnownStart.getMinValue(),
- KnownEnd.getMaxValue() + 1);
- CR = CR.intersectWith(R);
- }
+ return ConstantRange::getNonEmpty(KnownStart.getMinValue(),
+ KnownEnd.getMaxValue() + 1);
break;
}
case Instruction::LShr: {
@@ -5755,26 +5752,22 @@ getRangeForUnknownRecurrence(const SCEVUnknown *U) {
// Thus, the low end of the unsigned range is the last value produced.
auto KnownEnd = KnownBits::lshr(KnownStart,
KnownBits::makeConstant(TotalShift));
- auto R = ConstantRange::getNonEmpty(KnownEnd.getMinValue(),
- KnownStart.getMaxValue() + 1);
- CR = CR.intersectWith(R);
- break;
+ return ConstantRange::getNonEmpty(KnownEnd.getMinValue(),
+ KnownStart.getMaxValue() + 1);
}
case Instruction::Shl: {
// Iff no bits are shifted out, value increases on every shift.
auto KnownEnd = KnownBits::shl(KnownStart,
KnownBits::makeConstant(TotalShift));
if (TotalShift.ult(KnownStart.countMinLeadingZeros()))
- CR = CR.intersectWith(ConstantRange(KnownStart.getMinValue(),
- KnownEnd.getMaxValue() + 1));
+ return ConstantRange(KnownStart.getMinValue(),
+ KnownEnd.getMaxValue() + 1);
break;
}
};
- return CR;
+ return FullSet;
}
-
-
/// Determine the range for a particular SCEV. If SignHint is
/// HINT_RANGE_UNSIGNED (resp. HINT_RANGE_SIGNED) then getRange prefers ranges
/// with a "cleaner" unsigned (resp. signed) representation.
More information about the llvm-commits
mailing list