Skip to content

Commit

Permalink
[SCEV] Use APIntOps::umin to select best max BC count (NFC).
Browse files Browse the repository at this point in the history
Suggested in D102267, but I missed this in the committed version.
  • Loading branch information
fhahn committed Nov 12, 2021
1 parent 69c1cbe commit 819bca9
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Expand Up @@ -9615,9 +9615,7 @@ ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L, bool ControlsExit,
// N = Distance (as unsigned)
if (StepC->getValue()->isOne() || StepC->getValue()->isMinusOne()) {
APInt MaxBECount = getUnsignedRangeMax(applyLoopGuards(Distance, L));
APInt MaxBECountBase = getUnsignedRangeMax(Distance);
if (MaxBECountBase.ult(MaxBECount))
MaxBECount = MaxBECountBase;
MaxBECount = APIntOps::umin(MaxBECount, getUnsignedRangeMax(Distance));

// When a loop like "for (int i = 0; i != n; ++i) { /* body */ }" is rotated,
// we end up with a loop whose backedge-taken count is n - 1. Detect this
Expand Down Expand Up @@ -9650,11 +9648,7 @@ ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L, bool ControlsExit,
const SCEV *Max = getCouldNotCompute();
if (Exact != getCouldNotCompute()) {
APInt MaxInt = getUnsignedRangeMax(applyLoopGuards(Exact, L));
APInt BaseMaxInt = getUnsignedRangeMax(Exact);
if (BaseMaxInt.ult(MaxInt))
Max = getConstant(BaseMaxInt);
else
Max = getConstant(MaxInt);
Max = getConstant(APIntOps::umin(MaxInt, getUnsignedRangeMax(Exact)));
}
return ExitLimit(Exact, Max, false, Predicates);
}
Expand Down

0 comments on commit 819bca9

Please sign in to comment.