llvm.org GIT mirror llvm / f6d009f
Convert a few more backedge-taken count functions to use BackedgeTakenInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97042 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
2 changed file(s) with 16 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
304304 /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition
305305 /// of 'icmp op load X, cst', try to see if we can compute the
306306 /// backedge-taken count.
307 const SCEV *
307 BackedgeTakenInfo
308308 ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI,
309309 Constant *RHS,
310310 const Loop *L,
322322 /// HowFarToZero - Return the number of times a backedge comparing the
323323 /// specified value to zero will execute. If not computable, return
324324 /// CouldNotCompute.
325 const SCEV *HowFarToZero(const SCEV *V, const Loop *L);
325 BackedgeTakenInfo HowFarToZero(const SCEV *V, const Loop *L);
326326
327327 /// HowFarToNonZero - Return the number of times a backedge checking the
328328 /// specified value for nonzero will execute. If not computable, return
329329 /// CouldNotCompute.
330 const SCEV *HowFarToNonZero(const SCEV *V, const Loop *L);
330 BackedgeTakenInfo HowFarToNonZero(const SCEV *V, const Loop *L);
331331
332332 /// HowManyLessThans - Return the number of times a backedge containing the
333333 /// specified less-than comparison will execute. If not computable, return
37433743 // Handle common loops like: for (X = "string"; *X; ++X)
37443744 if (LoadInst *LI = dyn_cast(ExitCond->getOperand(0)))
37453745 if (Constant *RHS = dyn_cast(ExitCond->getOperand(1))) {
3746 const SCEV *ItCnt =
3746 BackedgeTakenInfo ItCnt =
37473747 ComputeLoadConstantCompareBackedgeTakenCount(LI, RHS, L, Cond);
3748 if (!isa(ItCnt)) {
3749 unsigned BitWidth = getTypeSizeInBits(ItCnt->getType());
3750 return BackedgeTakenInfo(ItCnt,
3751 isa(ItCnt) ? ItCnt :
3752 getConstant(APInt::getMaxValue(BitWidth)-1));
3753 }
3748 if (ItCnt.hasAnyInfo())
3749 return ItCnt;
37543750 }
37553751
37563752 const SCEV *LHS = getSCEV(ExitCond->getOperand(0));
37843780 switch (Cond) {
37853781 case ICmpInst::ICMP_NE: { // while (X != Y)
37863782 // Convert to: while (X-Y != 0)
3787 const SCEV *TC = HowFarToZero(getMinusSCEV(LHS, RHS), L);
3788 if (!isa(TC)) return TC;
3783 BackedgeTakenInfo BTI = HowFarToZero(getMinusSCEV(LHS, RHS), L);
3784 if (BTI.hasAnyInfo()) return BTI;
37893785 break;
37903786 }
37913787 case ICmpInst::ICMP_EQ: { // while (X == Y)
37923788 // Convert to: while (X-Y == 0)
3793 const SCEV *TC = HowFarToNonZero(getMinusSCEV(LHS, RHS), L);
3794 if (!isa(TC)) return TC;
3789 BackedgeTakenInfo BTI = HowFarToNonZero(getMinusSCEV(LHS, RHS), L);
3790 if (BTI.hasAnyInfo()) return BTI;
37953791 break;
37963792 }
37973793 case ICmpInst::ICMP_SLT: {
38783874 /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition of
38793875 /// 'icmp op load X, cst', try to see if we can compute the backedge
38803876 /// execution count.
3881 const SCEV *
3877 ScalarEvolution::BackedgeTakenInfo
38823878 ScalarEvolution::ComputeLoadConstantCompareBackedgeTakenCount(
38833879 LoadInst *LI,
38843880 Constant *RHS,
38873883 if (LI->isVolatile()) return getCouldNotCompute();
38883884
38893885 // Check to see if the loaded pointer is a getelementptr of a global.
3886 // TODO: Use SCEV instead of manually grubbing with GEPs.
38903887 GetElementPtrInst *GEP = dyn_cast(LI->getOperand(0));
38913888 if (!GEP) return getCouldNotCompute();
38923889
44514448
44524449 /// HowFarToZero - Return the number of times a backedge comparing the specified
44534450 /// value to zero will execute. If not computable, return CouldNotCompute.
4454 const SCEV *ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) {
4451 ScalarEvolution::BackedgeTakenInfo
4452 ScalarEvolution::HowFarToZero(const SCEV *V, const Loop *L) {
44554453 // If the value is a constant
44564454 if (const SCEVConstant *C = dyn_cast(V)) {
44574455 // If the value is already zero, the branch will execute zero times.
45314529 /// HowFarToNonZero - Return the number of times a backedge checking the
45324530 /// specified value for nonzero will execute. If not computable, return
45334531 /// CouldNotCompute
4534 const SCEV *ScalarEvolution::HowFarToNonZero(const SCEV *V, const Loop *L) {
4532 ScalarEvolution::BackedgeTakenInfo
4533 ScalarEvolution::HowFarToNonZero(const SCEV *V, const Loop *L) {
45354534 // Loops that look like: while (X == 0) are very strange indeed. We don't
45364535 // handle them yet except for the trivial case. This could be expanded in the
45374536 // future as needed.