Skip to content

Commit 4f5e9a2

Browse files
committed
[SCEV] Remove computeLoadConstantCompareExitLimit() (NFCI)
The functionality of this method is already covered by computeExitCountExhaustively() in a more general fashion. It was added at a time when exhaustive exit count calculation did not support constant folding loads yet. I double checked that dropping this code causes no binary changes in test-suite. Differential Revision: https://reviews.llvm.org/D112343
1 parent 4703a07 commit 4f5e9a2

File tree

2 files changed

+0
-96
lines changed

2 files changed

+0
-96
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,12 +1693,6 @@ class ScalarEvolution {
16931693
BasicBlock *ExitingBB,
16941694
bool IsSubExpr);
16951695

1696-
/// Given an exit condition of 'icmp op load X, cst', try to see if we can
1697-
/// compute the backedge-taken count.
1698-
ExitLimit computeLoadConstantCompareExitLimit(LoadInst *LI, Constant *RHS,
1699-
const Loop *L,
1700-
ICmpInst::Predicate p);
1701-
17021696
/// Compute the exit limit of a loop that is controlled by a
17031697
/// "(IV >> 1) != 0" type comparison. We cannot compute the exact trip
17041698
/// count in these cases (since SCEV has no way of expressing them), but we

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ using namespace PatternMatch;
139139

140140
#define DEBUG_TYPE "scalar-evolution"
141141

142-
STATISTIC(NumArrayLenItCounts,
143-
"Number of trip counts computed with array length");
144142
STATISTIC(NumTripCountsComputed,
145143
"Number of loops with predictable loop counts");
146144
STATISTIC(NumTripCountsNotComputed,
@@ -8116,15 +8114,6 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L,
81168114
Pred = ExitCond->getInversePredicate();
81178115
const ICmpInst::Predicate OriginalPred = Pred;
81188116

8119-
// Handle common loops like: for (X = "string"; *X; ++X)
8120-
if (LoadInst *LI = dyn_cast<LoadInst>(ExitCond->getOperand(0)))
8121-
if (Constant *RHS = dyn_cast<Constant>(ExitCond->getOperand(1))) {
8122-
ExitLimit ItCnt =
8123-
computeLoadConstantCompareExitLimit(LI, RHS, L, Pred);
8124-
if (ItCnt.hasAnyInfo())
8125-
return ItCnt;
8126-
}
8127-
81288117
const SCEV *LHS = getSCEV(ExitCond->getOperand(0));
81298118
const SCEV *RHS = getSCEV(ExitCond->getOperand(1));
81308119

@@ -8255,85 +8244,6 @@ EvaluateConstantChrecAtConstant(const SCEVAddRecExpr *AddRec, ConstantInt *C,
82558244
return cast<SCEVConstant>(Val)->getValue();
82568245
}
82578246

8258-
/// Given an exit condition of 'icmp op load X, cst', try to see if we can
8259-
/// compute the backedge execution count.
8260-
ScalarEvolution::ExitLimit
8261-
ScalarEvolution::computeLoadConstantCompareExitLimit(
8262-
LoadInst *LI,
8263-
Constant *RHS,
8264-
const Loop *L,
8265-
ICmpInst::Predicate predicate) {
8266-
if (LI->isVolatile()) return getCouldNotCompute();
8267-
8268-
// Check to see if the loaded pointer is a getelementptr of a global.
8269-
// TODO: Use SCEV instead of manually grubbing with GEPs.
8270-
GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(LI->getOperand(0));
8271-
if (!GEP) return getCouldNotCompute();
8272-
8273-
// Make sure that it is really a constant global we are gepping, with an
8274-
// initializer, and make sure the first IDX is really 0.
8275-
GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0));
8276-
if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
8277-
GEP->getNumOperands() < 3 || !isa<Constant>(GEP->getOperand(1)) ||
8278-
!cast<Constant>(GEP->getOperand(1))->isNullValue())
8279-
return getCouldNotCompute();
8280-
8281-
// Okay, we allow one non-constant index into the GEP instruction.
8282-
Value *VarIdx = nullptr;
8283-
std::vector<Constant*> Indexes;
8284-
unsigned VarIdxNum = 0;
8285-
for (unsigned i = 2, e = GEP->getNumOperands(); i != e; ++i)
8286-
if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(i))) {
8287-
Indexes.push_back(CI);
8288-
} else if (!isa<ConstantInt>(GEP->getOperand(i))) {
8289-
if (VarIdx) return getCouldNotCompute(); // Multiple non-constant idx's.
8290-
VarIdx = GEP->getOperand(i);
8291-
VarIdxNum = i-2;
8292-
Indexes.push_back(nullptr);
8293-
}
8294-
8295-
// Loop-invariant loads may be a byproduct of loop optimization. Skip them.
8296-
if (!VarIdx)
8297-
return getCouldNotCompute();
8298-
8299-
// Okay, we know we have a (load (gep GV, 0, X)) comparison with a constant.
8300-
// Check to see if X is a loop variant variable value now.
8301-
const SCEV *Idx = getSCEV(VarIdx);
8302-
Idx = getSCEVAtScope(Idx, L);
8303-
8304-
// We can only recognize very limited forms of loop index expressions, in
8305-
// particular, only affine AddRec's like {C1,+,C2}<L>.
8306-
const SCEVAddRecExpr *IdxExpr = dyn_cast<SCEVAddRecExpr>(Idx);
8307-
if (!IdxExpr || IdxExpr->getLoop() != L || !IdxExpr->isAffine() ||
8308-
isLoopInvariant(IdxExpr, L) ||
8309-
!isa<SCEVConstant>(IdxExpr->getOperand(0)) ||
8310-
!isa<SCEVConstant>(IdxExpr->getOperand(1)))
8311-
return getCouldNotCompute();
8312-
8313-
unsigned MaxSteps = MaxBruteForceIterations;
8314-
for (unsigned IterationNum = 0; IterationNum != MaxSteps; ++IterationNum) {
8315-
ConstantInt *ItCst = ConstantInt::get(
8316-
cast<IntegerType>(IdxExpr->getType()), IterationNum);
8317-
ConstantInt *Val = EvaluateConstantChrecAtConstant(IdxExpr, ItCst, *this);
8318-
8319-
// Form the GEP offset.
8320-
Indexes[VarIdxNum] = Val;
8321-
8322-
Constant *Result = ConstantFoldLoadThroughGEPIndices(GV->getInitializer(),
8323-
Indexes);
8324-
if (!Result) break; // Cannot compute!
8325-
8326-
// Evaluate the condition for this iteration.
8327-
Result = ConstantExpr::getICmp(predicate, Result, RHS);
8328-
if (!isa<ConstantInt>(Result)) break; // Couldn't decide for sure
8329-
if (cast<ConstantInt>(Result)->getValue().isMinValue()) {
8330-
++NumArrayLenItCounts;
8331-
return getConstant(ItCst); // Found terminating iteration!
8332-
}
8333-
}
8334-
return getCouldNotCompute();
8335-
}
8336-
83378247
ScalarEvolution::ExitLimit ScalarEvolution::computeShiftCompareExitLimit(
83388248
Value *LHS, Value *RHSV, const Loop *L, ICmpInst::Predicate Pred) {
83398249
ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV);

0 commit comments

Comments
 (0)