Skip to content

Commit a10aad8

Browse files
committed
Use reference again and use in howManyLessThans
1 parent 9c8dac0 commit a10aad8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,9 @@ class ScalarEvolution {
19601960
/// If \p AllowPredicates is set, this call will try to use a minimal set of
19611961
/// SCEV predicates in order to return an exact answer.
19621962
ExitLimit howManyLessThans(const SCEV *LHS, const SCEV *RHS, const Loop *L,
1963-
bool isSigned, bool ControlsOnlyExit,
1963+
bool isSigned,
1964+
function_ref<const LoopGuards &()> GetLoopGuards,
1965+
bool ControlsOnlyExit,
19641966
bool AllowPredicates = false);
19651967

19661968
ExitLimit howManyGreaterThans(const SCEV *LHS, const SCEV *RHS, const Loop *L,

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9317,8 +9317,8 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
93179317
case ICmpInst::ICMP_SLT:
93189318
case ICmpInst::ICMP_ULT: { // while (X < Y)
93199319
bool IsSigned = ICmpInst::isSigned(Pred);
9320-
ExitLimit EL = howManyLessThans(LHS, RHS, L, IsSigned, ControlsOnlyExit,
9321-
AllowPredicates);
9320+
ExitLimit EL = howManyLessThans(LHS, RHS, L, IsSigned, GetLoopGuards,
9321+
ControlsOnlyExit, AllowPredicates);
93229322
if (EL.hasAnyInfo())
93239323
return EL;
93249324
break;
@@ -10569,7 +10569,7 @@ ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L,
1056910569
if (!isLoopInvariant(Step, L))
1057010570
return getCouldNotCompute();
1057110571

10572-
LoopGuards Guards = GetLoopGuards();
10572+
const LoopGuards &Guards = GetLoopGuards();
1057310573
// Specialize step for this loop so we get context sensitive facts below.
1057410574
const SCEV *StepWLG = applyLoopGuards(Step, Guards);
1057510575

@@ -12928,10 +12928,10 @@ const SCEV *ScalarEvolution::computeMaxBECountForLT(const SCEV *Start,
1292812928
getConstant(StrideForMaxBECount) /* Step */);
1292912929
}
1293012930

12931-
ScalarEvolution::ExitLimit
12932-
ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
12933-
const Loop *L, bool IsSigned,
12934-
bool ControlsOnlyExit, bool AllowPredicates) {
12931+
ScalarEvolution::ExitLimit ScalarEvolution::howManyLessThans(
12932+
const SCEV *LHS, const SCEV *RHS, const Loop *L, bool IsSigned,
12933+
function_ref<const LoopGuards &()> GetLoopGuards, bool ControlsOnlyExit,
12934+
bool AllowPredicates) {
1293512935
SmallVector<const SCEVPredicate *> Predicates;
1293612936

1293712937
const SCEVAddRecExpr *IV = dyn_cast<SCEVAddRecExpr>(LHS);
@@ -12965,7 +12965,8 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1296512965
APInt StrideMax = getUnsignedRangeMax(AR->getStepRecurrence(*this));
1296612966
APInt Limit = APInt::getMaxValue(InnerBitWidth) - (StrideMax - 1);
1296712967
Limit = Limit.zext(OuterBitWidth);
12968-
return getUnsignedRangeMax(applyLoopGuards(RHS, L)).ule(Limit);
12968+
return getUnsignedRangeMax(applyLoopGuards(RHS, GetLoopGuards()))
12969+
.ule(Limit);
1296912970
};
1297012971
auto Flags = AR->getNoWrapFlags();
1297112972
if (!hasFlags(Flags, SCEV::FlagNUW) && canProveNUW())
@@ -13216,8 +13217,8 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
1321613217
if (!BECount) {
1321713218
auto canProveRHSGreaterThanEqualStart = [&]() {
1321813219
auto CondGE = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
13219-
const SCEV *GuardedRHS = applyLoopGuards(OrigRHS, L);
13220-
const SCEV *GuardedStart = applyLoopGuards(OrigStart, L);
13220+
const SCEV *GuardedRHS = applyLoopGuards(OrigRHS, GetLoopGuards());
13221+
const SCEV *GuardedStart = applyLoopGuards(OrigStart, GetLoopGuards());
1322113222

1322213223
if (isLoopEntryGuardedByCond(L, CondGE, OrigRHS, OrigStart) ||
1322313224
isKnownPredicate(CondGE, GuardedRHS, GuardedStart))

0 commit comments

Comments
 (0)