From: Dan Gohman Date: Tue, 24 Feb 2009 18:55:53 +0000 (+0000) Subject: Rename ScalarEvolution's getIterationCount to getBackedgeTakenCount, X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=46bdfb0e6bb9de86b19562fc52fddefd7014cf73;p=oota-llvm.git Rename ScalarEvolution's getIterationCount to getBackedgeTakenCount, to more accurately describe what it does. Expand its doxygen comment to describe what the backedge-taken count is and how it differs from the actual iteration count of the loop. Adjust names and comments in associated code accordingly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65382 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h index b001077ca7f..0b148da56f9 100644 --- a/include/llvm/Analysis/ScalarEvolution.h +++ b/include/llvm/Analysis/ScalarEvolution.h @@ -298,18 +298,28 @@ namespace llvm { bool isLoopGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, SCEV *LHS, SCEV *RHS); - /// getIterationCount - If the specified loop has a predictable iteration - /// count, return it, otherwise return a SCEVCouldNotCompute object. - SCEVHandle getIterationCount(const Loop *L) const; + /// getBackedgeTakenCount - If the specified loop has a predictable + /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute + /// object. The backedge-taken count is the number of times the loop header + /// will be branched to from within the loop. This is one less than the + /// trip count of the loop, since it doesn't count the first iteration, + /// when the header is branched to from outside the loop. + /// + /// Note that it is not valid to call this method on a loop without a + /// loop-invariant backedge-taken count (see + /// hasLoopInvariantBackedgeTakenCount). + /// + SCEVHandle getBackedgeTakenCount(const Loop *L) const; - /// hasLoopInvariantIterationCount - Return true if the specified loop has - /// an analyzable loop-invariant iteration count. - bool hasLoopInvariantIterationCount(const Loop *L) const; + /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop + /// has an analyzable loop-invariant backedge-taken count. + bool hasLoopInvariantBackedgeTakenCount(const Loop *L) const; - /// forgetLoopIterationCount - This method should be called by the + /// forgetLoopBackedgeTakenCount - This method should be called by the /// client when it has changed a loop in a way that may effect - /// ScalarEvolution's ability to compute a trip count. - void forgetLoopIterationCount(const Loop *L); + /// ScalarEvolution's ability to compute a trip count, or if the loop + /// is deleted. + void forgetLoopBackedgeTakenCount(const Loop *L); /// deleteValueFromRecords - This method should be called by the /// client before it removes a Value from the program, to make sure diff --git a/lib/Analysis/LoopVR.cpp b/lib/Analysis/LoopVR.cpp index d0b77b89f0a..3a7ec7b9886 100644 --- a/lib/Analysis/LoopVR.cpp +++ b/lib/Analysis/LoopVR.cpp @@ -27,7 +27,7 @@ static RegisterPass X("loopvr", "Loop Value Ranges", true, true); /// getRange - determine the range for a particular SCEV within a given Loop ConstantRange LoopVR::getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE) { - SCEVHandle T = SE.getIterationCount(L); + SCEVHandle T = SE.getBackedgeTakenCount(L); if (isa(T)) return ConstantRange(cast(S->getType())->getBitWidth(), true); diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 98668493434..067b83e466d 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -1419,9 +1419,9 @@ namespace { /// std::map Scalars; - /// IterationCounts - Cache the iteration count of the loops for this - /// function as they are computed. - std::map IterationCounts; + /// BackedgeTakenCounts - Cache the backedge-taken count of the loops for + /// this function as they are computed. + std::map BackedgeTakenCounts; /// ConstantEvolutionLoopExitValue - This map contains entries for all of /// the PHI instructions that we attempt to compute constant evolutions for. @@ -1464,19 +1464,28 @@ namespace { bool isLoopGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, SCEV *LHS, SCEV *RHS); - /// hasLoopInvariantIterationCount - Return true if the specified loop has - /// an analyzable loop-invariant iteration count. - bool hasLoopInvariantIterationCount(const Loop *L); + /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop + /// has an analyzable loop-invariant backedge-taken count. + bool hasLoopInvariantBackedgeTakenCount(const Loop *L); - /// forgetLoopIterationCount - This method should be called by the + /// forgetLoopBackedgeTakenCount - This method should be called by the /// client when it has changed a loop in a way that may effect - /// ScalarEvolution's ability to compute a trip count. - void forgetLoopIterationCount(const Loop *L); - - /// getIterationCount - If the specified loop has a predictable iteration - /// count, return it. Note that it is not valid to call this method on a - /// loop without a loop-invariant iteration count. - SCEVHandle getIterationCount(const Loop *L); + /// ScalarEvolution's ability to compute a trip count, or if the loop + /// is deleted. + void forgetLoopBackedgeTakenCount(const Loop *L); + + /// getBackedgeTakenCount - If the specified loop has a predictable + /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute + /// object. The backedge-taken count is the number of times the loop header + /// will be branched to from within the loop. This is one less than the + /// trip count of the loop, since it doesn't count the first iteration, + /// when the header is branched to from outside the loop. + /// + /// Note that it is not valid to call this method on a loop without a + /// loop-invariant backedge-taken count (see + /// hasLoopInvariantBackedgeTakenCount). + /// + SCEVHandle getBackedgeTakenCount(const Loop *L); /// deleteValueFromRecords - This method should be called by the /// client before it removes a value from the program, to make sure @@ -1500,24 +1509,25 @@ namespace { const SCEVHandle &SymName, const SCEVHandle &NewVal); - /// ComputeIterationCount - Compute the number of times the specified loop - /// will iterate. - SCEVHandle ComputeIterationCount(const Loop *L); + /// ComputeBackedgeTakenCount - Compute the number of times the specified + /// loop will iterate. + SCEVHandle ComputeBackedgeTakenCount(const Loop *L); - /// ComputeLoadConstantCompareIterationCount - Given an exit condition of - /// 'icmp op load X, cst', try to see if we can compute the trip count. - SCEVHandle ComputeLoadConstantCompareIterationCount(LoadInst *LI, - Constant *RHS, - const Loop *L, - ICmpInst::Predicate p); + /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition + /// of 'icmp op load X, cst', try to see if we can compute the trip count. + SCEVHandle + ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI, + Constant *RHS, + const Loop *L, + ICmpInst::Predicate p); - /// ComputeIterationCountExhaustively - If the trip is known to execute a - /// constant number of times (the condition evolves only from constants), + /// ComputeBackedgeTakenCountExhaustively - If the trip is known to execute + /// a constant number of times (the condition evolves only from constants), /// try to evaluate a few iterations of the loop until we get the exit /// condition gets a value of ExitWhen (true or false). If we cannot /// evaluate the trip count of the loop, return UnknownValue. - SCEVHandle ComputeIterationCountExhaustively(const Loop *L, Value *Cond, - bool ExitWhen); + SCEVHandle ComputeBackedgeTakenCountExhaustively(const Loop *L, Value *Cond, + bool ExitWhen); /// HowFarToZero - Return the number of times a backedge comparing the /// specified value to zero will execute. If not computable, return @@ -1545,7 +1555,7 @@ namespace { /// in the header of its containing loop, we know the loop executes a /// constant number of times, and the PHI node is just a recurrence /// involving constants, fold it. - Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& Its, + Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs, const Loop *L); }; } @@ -1931,14 +1941,22 @@ SCEVHandle ScalarEvolutionsImpl::createSCEV(Value *V) { // Iteration Count Computation Code // -/// getIterationCount - If the specified loop has a predictable iteration -/// count, return it. Note that it is not valid to call this method on a -/// loop without a loop-invariant iteration count. -SCEVHandle ScalarEvolutionsImpl::getIterationCount(const Loop *L) { - std::map::iterator I = IterationCounts.find(L); - if (I == IterationCounts.end()) { - SCEVHandle ItCount = ComputeIterationCount(L); - I = IterationCounts.insert(std::make_pair(L, ItCount)).first; +/// getBackedgeTakenCount - If the specified loop has a predictable +/// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute +/// object. The backedge-taken count is the number of times the loop header +/// will be branched to from within the loop. This is one less than the +/// trip count of the loop, since it doesn't count the first iteration, +/// when the header is branched to from outside the loop. +/// +/// Note that it is not valid to call this method on a loop without a +/// loop-invariant backedge-taken count (see +/// hasLoopInvariantBackedgeTakenCount). +/// +SCEVHandle ScalarEvolutionsImpl::getBackedgeTakenCount(const Loop *L) { + std::map::iterator I = BackedgeTakenCounts.find(L); + if (I == BackedgeTakenCounts.end()) { + SCEVHandle ItCount = ComputeBackedgeTakenCount(L); + I = BackedgeTakenCounts.insert(std::make_pair(L, ItCount)).first; if (ItCount != UnknownValue) { assert(ItCount->isLoopInvariant(L) && "Computed trip count isn't loop invariant for loop!"); @@ -1951,16 +1969,17 @@ SCEVHandle ScalarEvolutionsImpl::getIterationCount(const Loop *L) { return I->second; } -/// forgetLoopIterationCount - This method should be called by the +/// forgetLoopBackedgeTakenCount - This method should be called by the /// client when it has changed a loop in a way that may effect -/// ScalarEvolution's ability to compute a trip count. -void ScalarEvolutionsImpl::forgetLoopIterationCount(const Loop *L) { - IterationCounts.erase(L); +/// ScalarEvolution's ability to compute a trip count, or if the loop +/// is deleted. +void ScalarEvolutionsImpl::forgetLoopBackedgeTakenCount(const Loop *L) { + BackedgeTakenCounts.erase(L); } -/// ComputeIterationCount - Compute the number of times the specified loop -/// will iterate. -SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { +/// ComputeBackedgeTakenCount - Compute the number of times the backedge +/// of the specified loop will execute. +SCEVHandle ScalarEvolutionsImpl::ComputeBackedgeTakenCount(const Loop *L) { // If the loop has a non-one exit block count, we can't analyze it. SmallVector ExitBlocks; L->getExitBlocks(ExitBlocks); @@ -2010,7 +2029,7 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { // Note that ICmpInst deals with pointer comparisons too so we must check // the type of the operand. if (ExitCond == 0 || isa(ExitCond->getOperand(0)->getType())) - return ComputeIterationCountExhaustively(L, ExitBr->getCondition(), + return ComputeBackedgeTakenCountExhaustively(L, ExitBr->getCondition(), ExitBr->getSuccessor(0) == ExitBlock); // If the condition was exit on true, convert the condition to exit on false @@ -2024,7 +2043,7 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { if (LoadInst *LI = dyn_cast(ExitCond->getOperand(0))) if (Constant *RHS = dyn_cast(ExitCond->getOperand(1))) { SCEVHandle ItCnt = - ComputeLoadConstantCompareIterationCount(LI, RHS, L, Cond); + ComputeLoadConstantCompareBackedgeTakenCount(LI, RHS, L, Cond); if (!isa(ItCnt)) return ItCnt; } @@ -2107,7 +2126,7 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { } default: #if 0 - cerr << "ComputeIterationCount "; + cerr << "ComputeBackedgeTakenCount "; if (ExitCond->getOperand(0)->getType()->isUnsigned()) cerr << "[unsigned] "; cerr << *LHS << " " @@ -2116,8 +2135,9 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) { #endif break; } - return ComputeIterationCountExhaustively(L, ExitCond, - ExitBr->getSuccessor(0) == ExitBlock); + return + ComputeBackedgeTakenCountExhaustively(L, ExitCond, + ExitBr->getSuccessor(0) == ExitBlock); } static ConstantInt * @@ -2164,12 +2184,13 @@ GetAddressedElementFromGlobal(GlobalVariable *GV, return Init; } -/// ComputeLoadConstantCompareIterationCount - Given an exit condition of -/// 'icmp op load X, cst', try to see if we can compute the trip count. +/// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition of +/// 'icmp op load X, cst', try to see if we can compute the backedge +/// execution count. SCEVHandle ScalarEvolutionsImpl:: -ComputeLoadConstantCompareIterationCount(LoadInst *LI, Constant *RHS, - const Loop *L, - ICmpInst::Predicate predicate) { +ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI, Constant *RHS, + const Loop *L, + ICmpInst::Predicate predicate) { if (LI->isVolatile()) return UnknownValue; // Check to see if the loaded pointer is a getelementptr of a global. @@ -2326,13 +2347,13 @@ static Constant *EvaluateExpression(Value *V, Constant *PHIVal) { /// constant number of times, and the PHI node is just a recurrence /// involving constants, fold it. Constant *ScalarEvolutionsImpl:: -getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& Its, const Loop *L){ +getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs, const Loop *L){ std::map::iterator I = ConstantEvolutionLoopExitValue.find(PN); if (I != ConstantEvolutionLoopExitValue.end()) return I->second; - if (Its.ugt(APInt(Its.getBitWidth(),MaxBruteForceIterations))) + if (BEs.ugt(APInt(BEs.getBitWidth(),MaxBruteForceIterations))) return ConstantEvolutionLoopExitValue[PN] = 0; // Not going to evaluate it. Constant *&RetVal = ConstantEvolutionLoopExitValue[PN]; @@ -2352,10 +2373,10 @@ getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& Its, const Loop *L){ return RetVal = 0; // Not derived from same PHI. // Execute the loop symbolically to determine the exit value. - if (Its.getActiveBits() >= 32) + if (BEs.getActiveBits() >= 32) return RetVal = 0; // More than 2^32-1 iterations?? Not doing it! - unsigned NumIterations = Its.getZExtValue(); // must be in range + unsigned NumIterations = BEs.getZExtValue(); // must be in range unsigned IterationNum = 0; for (Constant *PHIVal = StartCST; ; ++IterationNum) { if (IterationNum == NumIterations) @@ -2371,13 +2392,13 @@ getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& Its, const Loop *L){ } } -/// ComputeIterationCountExhaustively - If the trip is known to execute a +/// ComputeBackedgeTakenCountExhaustively - If the trip is known to execute a /// constant number of times (the condition evolves only from constants), /// try to evaluate a few iterations of the loop until we get the exit /// condition gets a value of ExitWhen (true or false). If we cannot /// evaluate the trip count of the loop, return UnknownValue. SCEVHandle ScalarEvolutionsImpl:: -ComputeIterationCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen) { +ComputeBackedgeTakenCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen) { PHINode *PN = getConstantEvolvingPHI(Cond, L); if (PN == 0) return UnknownValue; @@ -2440,15 +2461,17 @@ SCEVHandle ScalarEvolutionsImpl::getSCEVAtScope(SCEV *V, const Loop *L) { if (PHINode *PN = dyn_cast(I)) if (PN->getParent() == LI->getHeader()) { // Okay, there is no closed form solution for the PHI node. Check - // to see if the loop that contains it has a known iteration count. - // If so, we may be able to force computation of the exit value. - SCEVHandle IterationCount = getIterationCount(LI); - if (SCEVConstant *ICC = dyn_cast(IterationCount)) { + // to see if the loop that contains it has a known backedge-taken + // count. If so, we may be able to force computation of the exit + // value. + SCEVHandle BackedgeTakenCount = getBackedgeTakenCount(LI); + if (SCEVConstant *BTCC = + dyn_cast(BackedgeTakenCount)) { // Okay, we know how many times the containing loop executes. If // this is a constant evolving PHI node, get the final value at // the specified iteration number. Constant *RV = getConstantEvolutionLoopExitValue(PN, - ICC->getValue()->getValue(), + BTCC->getValue()->getValue(), LI); if (RV) return SE.getUnknown(RV); } @@ -2552,11 +2575,11 @@ SCEVHandle ScalarEvolutionsImpl::getSCEVAtScope(SCEV *V, const Loop *L) { if (!L || !AddRec->getLoop()->contains(L->getHeader())) { // To evaluate this recurrence, we need to know how many times the AddRec // loop iterates. Compute this now. - SCEVHandle IterationCount = getIterationCount(AddRec->getLoop()); - if (IterationCount == UnknownValue) return UnknownValue; + SCEVHandle BackedgeTakenCount = getBackedgeTakenCount(AddRec->getLoop()); + if (BackedgeTakenCount == UnknownValue) return UnknownValue; // Then, evaluate the AddRec. - return AddRec->evaluateAtIteration(IterationCount, SE); + return AddRec->evaluateAtIteration(BackedgeTakenCount, SE); } return UnknownValue; } @@ -3110,16 +3133,16 @@ bool ScalarEvolution::isLoopGuardedByCond(const Loop *L, LHS, RHS); } -SCEVHandle ScalarEvolution::getIterationCount(const Loop *L) const { - return ((ScalarEvolutionsImpl*)Impl)->getIterationCount(L); +SCEVHandle ScalarEvolution::getBackedgeTakenCount(const Loop *L) const { + return ((ScalarEvolutionsImpl*)Impl)->getBackedgeTakenCount(L); } -bool ScalarEvolution::hasLoopInvariantIterationCount(const Loop *L) const { - return !isa(getIterationCount(L)); +bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount(const Loop *L) const { + return !isa(getBackedgeTakenCount(L)); } -void ScalarEvolution::forgetLoopIterationCount(const Loop *L) { - return ((ScalarEvolutionsImpl*)Impl)->forgetLoopIterationCount(L); +void ScalarEvolution::forgetLoopBackedgeTakenCount(const Loop *L) { + return ((ScalarEvolutionsImpl*)Impl)->forgetLoopBackedgeTakenCount(L); } SCEVHandle ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) const { @@ -3143,10 +3166,10 @@ static void PrintLoopInfo(std::ostream &OS, const ScalarEvolution *SE, if (ExitBlocks.size() != 1) OS << " "; - if (SE->hasLoopInvariantIterationCount(L)) { - OS << *SE->getIterationCount(L) << " iterations! "; + if (SE->hasLoopInvariantBackedgeTakenCount(L)) { + OS << "backedge-taken count is " << *SE->getBackedgeTakenCount(L); } else { - OS << "Unpredictable iteration count. "; + OS << "Unpredictable backedge-taken count. "; } OS << "\n"; diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 6b52ed7b84d..205efca6ce2 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -93,12 +93,12 @@ namespace { void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader, SmallPtrSet &DeadInsts); - void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount, + void LinearFunctionTestReplace(Loop *L, SCEVHandle BackedgeTakenCount, Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, SCEVExpander &Rewriter); - void RewriteLoopExitValues(Loop *L, SCEV *IterationCount); + void RewriteLoopExitValues(Loop *L, SCEV *BackedgeTakenCount); void DeleteTriviallyDeadInstructions(SmallPtrSet &Insts); @@ -232,7 +232,7 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN, /// SCEV analysis can determine a loop-invariant trip count of the loop, which /// is actually a much broader range than just linear tests. void IndVarSimplify::LinearFunctionTestReplace(Loop *L, - SCEVHandle IterationCount, + SCEVHandle BackedgeTakenCount, Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, @@ -241,43 +241,41 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, // against the preincremented value, otherwise we prefer to compare against // the post-incremented value. Value *CmpIndVar; + SCEVHandle RHS = BackedgeTakenCount; if (ExitingBlock == L->getLoopLatch()) { - // What ScalarEvolution calls the "iteration count" is actually the - // number of times the branch is taken. Add one to get the number - // of times the branch is executed. If this addition may overflow, - // we have to be more pessimistic and cast the induction variable - // before doing the add. - SCEVHandle Zero = SE->getIntegerSCEV(0, IterationCount->getType()); + // Add one to the "backedge-taken" count to get the trip count. + // If this addition may overflow, we have to be more pessimistic and + // cast the induction variable before doing the add. + SCEVHandle Zero = SE->getIntegerSCEV(0, BackedgeTakenCount->getType()); SCEVHandle N = - SE->getAddExpr(IterationCount, - SE->getIntegerSCEV(1, IterationCount->getType())); + SE->getAddExpr(BackedgeTakenCount, + SE->getIntegerSCEV(1, BackedgeTakenCount->getType())); if ((isa(N) && !N->isZero()) || SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) { // No overflow. Cast the sum. - IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType()); + RHS = SE->getTruncateOrZeroExtend(N, IndVar->getType()); } else { // Potential overflow. Cast before doing the add. - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, - IndVar->getType()); - IterationCount = - SE->getAddExpr(IterationCount, - SE->getIntegerSCEV(1, IndVar->getType())); + RHS = SE->getTruncateOrZeroExtend(BackedgeTakenCount, + IndVar->getType()); + RHS = SE->getAddExpr(RHS, + SE->getIntegerSCEV(1, IndVar->getType())); } - // The IterationCount expression contains the number of times that the - // backedge actually branches to the loop header. This is one less than the - // number of times the loop executes, so add one to it. + // The BackedgeTaken expression contains the number of times that the + // backedge branches to the loop header. This is one less than the + // number of times the loop executes, so use the incremented indvar. CmpIndVar = L->getCanonicalInductionVariableIncrement(); } else { // We have to use the preincremented value... - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, - IndVar->getType()); + RHS = SE->getTruncateOrZeroExtend(BackedgeTakenCount, + IndVar->getType()); CmpIndVar = IndVar; } // Expand the code for the iteration count into the preheader of the loop. BasicBlock *Preheader = L->getLoopPreheader(); - Value *ExitCnt = Rewriter.expandCodeFor(IterationCount, + Value *ExitCnt = Rewriter.expandCodeFor(RHS, Preheader->getTerminator()); // Insert a new icmp_ne or icmp_eq instruction before the branch. @@ -291,7 +289,7 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, << " LHS:" << *CmpIndVar // includes a newline << " op:\t" << (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n" - << " RHS:\t" << *IterationCount << "\n"; + << " RHS:\t" << *RHS << "\n"; Value *Cond = new ICmpInst(Opcode, CmpIndVar, ExitCnt, "exitcond", BI); BI->setCondition(Cond); @@ -304,7 +302,7 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, /// final value of any expressions that are recurrent in the loop, and /// substitute the exit values from the loop into any instructions outside of /// the loop that use the final values of the current expressions. -void IndVarSimplify::RewriteLoopExitValues(Loop *L, SCEV *IterationCount) { +void IndVarSimplify::RewriteLoopExitValues(Loop *L, SCEV *BackedgeTakenCount) { BasicBlock *Preheader = L->getLoopPreheader(); // Scan all of the instructions in the loop, looking at those that have @@ -322,7 +320,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L, SCEV *IterationCount) { BlockToInsertInto = Preheader; BasicBlock::iterator InsertPt = BlockToInsertInto->getFirstNonPHI(); - bool HasConstantItCount = isa(IterationCount); + bool HasConstantItCount = isa(BackedgeTakenCount); SmallPtrSet InstructionsToDelete; std::map ExitValues; @@ -435,7 +433,7 @@ void IndVarSimplify::RewriteNonIntegerIVs(Loop *L) { // may not have been able to compute a trip count. Now that we've done some // re-writing, the trip count may be computable. if (Changed) - SE->forgetLoopIterationCount(L); + SE->forgetLoopBackedgeTakenCount(L); if (!DeadInsts.empty()) DeleteTriviallyDeadInstructions(DeadInsts); @@ -473,7 +471,8 @@ static const Type *getEffectiveIndvarType(const PHINode *Phi) { /// variables, return the PHI for this induction variable. /// /// TODO: This duplicates a fair amount of ScalarEvolution logic. -/// Perhaps this can be merged with ScalarEvolution::getIterationCount +/// Perhaps this can be merged with +/// ScalarEvolution::getBackedgeTakenCount /// and/or ScalarEvolution::get{Sign,Zero}ExtendExpr. /// static const PHINode *TestOrigIVForWrap(const Loop *L, @@ -622,9 +621,9 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // loop into any instructions outside of the loop that use the final values of // the current expressions. // - SCEVHandle IterationCount = SE->getIterationCount(L); - if (!isa(IterationCount)) - RewriteLoopExitValues(L, IterationCount); + SCEVHandle BackedgeTakenCount = SE->getBackedgeTakenCount(L); + if (!isa(BackedgeTakenCount)) + RewriteLoopExitValues(L, BackedgeTakenCount); // Next, analyze all of the induction variables in the loop, canonicalizing // auxillary induction variables. @@ -649,9 +648,9 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // the set of the types of the other recurrence expressions. const Type *LargestType = 0; SmallSetVector SizesToInsert; - if (!isa(IterationCount)) { - LargestType = IterationCount->getType(); - SizesToInsert.insert(IterationCount->getType()); + if (!isa(BackedgeTakenCount)) { + LargestType = BackedgeTakenCount->getType(); + SizesToInsert.insert(BackedgeTakenCount->getType()); } for (unsigned i = 0, e = IndVars.size(); i != e; ++i) { const PHINode *PN = IndVars[i].first; @@ -682,7 +681,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { bool NoSignedWrap = false; bool NoUnsignedWrap = false; const PHINode *OrigControllingPHI = 0; - if (!isa(IterationCount) && ExitingBlock) + if (!isa(BackedgeTakenCount) && ExitingBlock) // Can't rewrite non-branch yet. if (BranchInst *BI = dyn_cast(ExitingBlock->getTerminator())) { if (Instruction *OrigCond = dyn_cast(BI->getCondition())) { @@ -695,7 +694,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { DeadInsts.insert(OrigCond); } - LinearFunctionTestReplace(L, IterationCount, IndVar, + LinearFunctionTestReplace(L, BackedgeTakenCount, IndVar, ExitingBlock, BI, Rewriter); } diff --git a/lib/Transforms/Scalar/LoopDeletion.cpp b/lib/Transforms/Scalar/LoopDeletion.cpp index b64131cf18c..d7be820e74f 100644 --- a/lib/Transforms/Scalar/LoopDeletion.cpp +++ b/lib/Transforms/Scalar/LoopDeletion.cpp @@ -190,7 +190,7 @@ bool LoopDeletion::runOnLoop(Loop* L, LPPassManager& LPM) { // Don't remove loops for which we can't solve the trip count. // They could be infinite, in which case we'd be changing program behavior. ScalarEvolution& SE = getAnalysis(); - SCEVHandle S = SE.getIterationCount(L); + SCEVHandle S = SE.getBackedgeTakenCount(L); if (isa(S)) return false; @@ -267,7 +267,7 @@ bool LoopDeletion::runOnLoop(Loop* L, LPPassManager& LPM) { (*LI)->eraseFromParent(); // Tell ScalarEvolution that the loop is deleted. - SE.forgetLoopIterationCount(L); + SE.forgetLoopBackedgeTakenCount(L); // Finally, the blocks from loopinfo. This has to happen late because // otherwise our loop iterators won't work. diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 0d6df2fbae3..641f9b0e5c1 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2351,13 +2351,13 @@ ICmpInst *LoopStrengthReduce::OptimizeSMax(Loop *L, ICmpInst *Cond, SelectInst *Sel = dyn_cast(Cond->getOperand(1)); if (!Sel || !Sel->hasOneUse()) return Cond; - SCEVHandle IterationCount = SE->getIterationCount(L); - if (isa(IterationCount)) + SCEVHandle BackedgeTakenCount = SE->getBackedgeTakenCount(L); + if (isa(BackedgeTakenCount)) return Cond; - SCEVHandle One = SE->getIntegerSCEV(1, IterationCount->getType()); + SCEVHandle One = SE->getIntegerSCEV(1, BackedgeTakenCount->getType()); - // Adjust for an annoying getIterationCount quirk. - IterationCount = SE->getAddExpr(IterationCount, One); + // Add one to the backedge-taken count to get the trip count. + SCEVHandle IterationCount = SE->getAddExpr(BackedgeTakenCount, One); // Check for a max calculation that matches the pattern. SCEVSMaxExpr *SMax = dyn_cast(IterationCount); @@ -2412,8 +2412,8 @@ ICmpInst *LoopStrengthReduce::OptimizeSMax(Loop *L, ICmpInst *Cond, /// inside the loop then try to eliminate the cast opeation. void LoopStrengthReduce::OptimizeShadowIV(Loop *L) { - SCEVHandle IterationCount = SE->getIterationCount(L); - if (isa(IterationCount)) + SCEVHandle BackedgeTakenCount = SE->getBackedgeTakenCount(L); + if (isa(BackedgeTakenCount)) return; for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e; diff --git a/test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll b/test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll index b38db50c4c3..a2cbcee244b 100644 --- a/test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll +++ b/test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \ -; RUN: -scalar-evolution-max-iterations=0 | grep {Loop bb: 100 iterations} +; RUN: -scalar-evolution-max-iterations=0 | grep {Loop bb: backedge-taken count is 100} ; PR1533 @array = weak global [101 x i32] zeroinitializer, align 32 ; <[100 x i32]*> [#uses=1] diff --git a/test/Analysis/ScalarEvolution/2007-08-06-Unsigned.ll b/test/Analysis/ScalarEvolution/2007-08-06-Unsigned.ll index d4452f4f3eb..34d97664ccb 100644 --- a/test/Analysis/ScalarEvolution/2007-08-06-Unsigned.ll +++ b/test/Analysis/ScalarEvolution/2007-08-06-Unsigned.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb: (-1 + (-1 \\* %x) + %y) iterations!} +; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb: backedge-taken count is (-1 + (-1 \\* %x) + %y)} ; PR1597 define i32 @f(i32 %x, i32 %y) { diff --git a/test/Analysis/ScalarEvolution/2007-09-27-LargeStepping.ll b/test/Analysis/ScalarEvolution/2007-09-27-LargeStepping.ll index fcdc85052e8..c4de0937559 100644 --- a/test/Analysis/ScalarEvolution/2007-09-27-LargeStepping.ll +++ b/test/Analysis/ScalarEvolution/2007-09-27-LargeStepping.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \ -; RUN: -scalar-evolution-max-iterations=0 | grep {13 iterations} +; RUN: -scalar-evolution-max-iterations=0 | grep {backedge-taken count is 13} ; PR1706 define i32 @f() { diff --git a/test/Analysis/ScalarEvolution/2008-02-11-ReversedCondition.ll b/test/Analysis/ScalarEvolution/2008-02-11-ReversedCondition.ll index a01007d8c2a..182a0876e65 100644 --- a/test/Analysis/ScalarEvolution/2008-02-11-ReversedCondition.ll +++ b/test/Analysis/ScalarEvolution/2008-02-11-ReversedCondition.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop header: (0 smax %n) iterations!} +; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop header: backedge-taken count is (0 smax %n)} define void @foo(i32 %n) { entry: diff --git a/test/Analysis/ScalarEvolution/2008-02-12-SMAXTripCount.ll b/test/Analysis/ScalarEvolution/2008-02-12-SMAXTripCount.ll index 74e826847b3..cd3a80f7919 100644 --- a/test/Analysis/ScalarEvolution/2008-02-12-SMAXTripCount.ll +++ b/test/Analysis/ScalarEvolution/2008-02-12-SMAXTripCount.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop loop: (100 + (-100 smax %n)) iterations!} +; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop loop: backedge-taken count is (100 + (-100 smax %n))} ; PR2002 define void @foo(i8 %n) { diff --git a/test/Analysis/ScalarEvolution/2008-05-25-NegativeStepToZero.ll b/test/Analysis/ScalarEvolution/2008-05-25-NegativeStepToZero.ll index 228de9e509e..13852d45652 100644 --- a/test/Analysis/ScalarEvolution/2008-05-25-NegativeStepToZero.ll +++ b/test/Analysis/ScalarEvolution/2008-05-25-NegativeStepToZero.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \ -; RUN: -scalar-evolution-max-iterations=0 | grep {61 iterations} +; RUN: -scalar-evolution-max-iterations=0 | grep {backedge-taken count is 61} ; PR2364 define i32 @func_6() nounwind { diff --git a/test/Analysis/ScalarEvolution/2008-07-19-WrappingIV.ll b/test/Analysis/ScalarEvolution/2008-07-19-WrappingIV.ll index ce03db050e4..9ba118c1506 100644 --- a/test/Analysis/ScalarEvolution/2008-07-19-WrappingIV.ll +++ b/test/Analysis/ScalarEvolution/2008-07-19-WrappingIV.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \ -; RUN: -scalar-evolution-max-iterations=0 | grep {113 iterations} +; RUN: -scalar-evolution-max-iterations=0 | grep {backedge-taken count is 113} ; PR2088 define void @fun() { diff --git a/test/Analysis/ScalarEvolution/2008-07-29-SGTTripCount.ll b/test/Analysis/ScalarEvolution/2008-07-29-SGTTripCount.ll index bb352a55a3b..527b8b0add2 100644 --- a/test/Analysis/ScalarEvolution/2008-07-29-SGTTripCount.ll +++ b/test/Analysis/ScalarEvolution/2008-07-29-SGTTripCount.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output \ ; RUN: -scalar-evolution-max-iterations=0 | \ -; RUN: grep -F "(-1 + (-1 * %j)) iterations" +; RUN: grep -F "backedge-taken count is (-1 + (-1 * %j))" ; PR2607 define i32 @_Z1aj(i32 %j) nounwind { diff --git a/test/Analysis/ScalarEvolution/2008-07-29-SMinExpr.ll b/test/Analysis/ScalarEvolution/2008-07-29-SMinExpr.ll index a1025ddda09..a90c8049027 100644 --- a/test/Analysis/ScalarEvolution/2008-07-29-SMinExpr.ll +++ b/test/Analysis/ScalarEvolution/2008-07-29-SMinExpr.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution -disable-output \ ; RUN: -scalar-evolution-max-iterations=0 | \ -; RUN: grep -F "(-2147483632 + (2147483632 smax (-1 + (-1 * %x)) smax (-1 + (-1 * %y)))) iterations" +; RUN: grep -F "backedge-taken count is (-2147483632 + (2147483632 smax (-1 + (-1 * %x)) smax (-1 + (-1 * %y))))" ; PR2607 define i32 @b(i32 %x, i32 %y) { diff --git a/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll b/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll index 5de246e52cf..0651fd85487 100644 --- a/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll +++ b/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution |& \ -; RUN: grep {Loop bb: (7 + (-1 \\* %argc)) iterations!} +; RUN: grep {Loop bb: backedge-taken count is (7 + (-1 \\* %argc))} ; XFAIL: * define i32 @main(i32 %argc, i8** %argv) nounwind { diff --git a/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll b/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll index 1bf24d7f487..3df1fe00013 100644 --- a/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll +++ b/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {255 iterations} +; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {backedge-taken count is 255} ; XFAIL: * define i32 @foo(i32 %x, i32 %y, i32* %lam, i32* %alp) nounwind { diff --git a/test/Analysis/ScalarEvolution/SolveQuadraticEquation.ll b/test/Analysis/ScalarEvolution/SolveQuadraticEquation.ll index 26550fd795b..76ca4a08474 100644 --- a/test/Analysis/ScalarEvolution/SolveQuadraticEquation.ll +++ b/test/Analysis/ScalarEvolution/SolveQuadraticEquation.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \ -; RUN: -scalar-evolution-max-iterations=0 | grep {100 iterations} +; RUN: -scalar-evolution-max-iterations=0 | grep {backedge-taken count is 100} ; PR1101 @A = weak global [1000 x i32] zeroinitializer, align 32 diff --git a/test/Analysis/ScalarEvolution/avoid-smax-0.ll b/test/Analysis/ScalarEvolution/avoid-smax-0.ll index a8c5aba73de..df39cc0af08 100644 --- a/test/Analysis/ScalarEvolution/avoid-smax-0.ll +++ b/test/Analysis/ScalarEvolution/avoid-smax-0.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb3: (-1 + %n) iterations!} +; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop bb3: backedge-taken count is (-1 + %n)} ; We don't want to use a max in the trip count expression in ; this testcase. diff --git a/test/Analysis/ScalarEvolution/trip-count.ll b/test/Analysis/ScalarEvolution/trip-count.ll index ded14c32018..f8894d6428f 100644 --- a/test/Analysis/ScalarEvolution/trip-count.ll +++ b/test/Analysis/ScalarEvolution/trip-count.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution \ -; RUN: -scalar-evolution-max-iterations=0 | grep {10000 iterations} +; RUN: -scalar-evolution-max-iterations=0 | grep {backedge-taken count is 10000} ; PR1101 @A = weak global [1000 x i32] zeroinitializer, align 32 diff --git a/test/Analysis/ScalarEvolution/trip-count2.ll b/test/Analysis/ScalarEvolution/trip-count2.ll index 5ca58a24ce0..8615c76db69 100644 --- a/test/Analysis/ScalarEvolution/trip-count2.ll +++ b/test/Analysis/ScalarEvolution/trip-count2.ll @@ -1,5 +1,5 @@ ; RUN: llvm-as < %s | opt -analyze -scalar-evolution | \ -; RUN: grep {4 iterations} +; RUN: grep {backedge-taken count is 4} ; PR1101 @A = weak global [1000 x i32] zeroinitializer, align 32