@@ -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");
144142STATISTIC(NumTripCountsComputed,
145143 "Number of loops with predictable loop counts");
146144STATISTIC(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-
83378247ScalarEvolution::ExitLimit ScalarEvolution::computeShiftCompareExitLimit(
83388248 Value *LHS, Value *RHSV, const Loop *L, ICmpInst::Predicate Pred) {
83398249 ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV);
0 commit comments