llvm.org GIT mirror llvm / e2b8290
[LFTR] Rename variable to minimize confusion [NFC] As pointed out by Nikita in D62625, BackedgeTakenCount is generally used to refer to the backedge taken count of the loop. A conditional backedge taken count - one which only applies if a particular exit is taken - is called a ExitCount in SCEV code, so be consistent here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363293 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 4 months ago
1 changed file(s) with 15 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
150150 bool hasHardUserWithinLoop(const Loop *L, const Instruction *I) const;
151151
152152 bool linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB,
153 const SCEV *BackedgeTakenCount,
153 const SCEV *ExitCount,
154154 PHINode *IndVar, SCEVExpander &Rewriter);
155155
156156 bool sinkUnusedInvariants(Loop *L);
23812381 /// determine a loop-invariant trip count of the loop, which is actually a much
23822382 /// broader range than just linear tests.
23832383 bool IndVarSimplify::
2384 linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB,
2385 const SCEV *BackedgeTakenCount,
2384 linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, const SCEV *ExitCount,
23862385 PHINode *IndVar, SCEVExpander &Rewriter) {
23872386 assert(isLoopCounter(IndVar, L, SE));
23882387 assert(L->getLoopLatch() && "Loop no longer in simplified form?");
23912390
23922391 // Initialize CmpIndVar and IVCount to their preincremented values.
23932392 Value *CmpIndVar = IndVar;
2394 const SCEV *IVCount = BackedgeTakenCount;
2393 const SCEV *IVCount = ExitCount;
23952394
23962395 // If the exiting block is the same as the backedge block, we prefer to
23972396 // compare against the post-incremented value, otherwise we must compare
24112410 if (SafeToPostInc) {
24122411 // Add one to the "backedge-taken" count to get the trip count.
24132412 // This addition may overflow, which is valid as long as the comparison
2414 // is truncated to BackedgeTakenCount->getType().
2415 IVCount = SE->getAddExpr(BackedgeTakenCount,
2416 SE->getOne(BackedgeTakenCount->getType()));
2417 // The BackedgeTaken expression contains the number of times that the
2413 // is truncated to ExitCount->getType().
2414 IVCount = SE->getAddExpr(ExitCount, SE->getOne(ExitCount->getType()));
2415 // The ExitCount expression contains the number of times that the
24182416 // backedge branches to the loop header. This is one less than the
24192417 // number of times the loop executes, so use the incremented indvar.
24202418 CmpIndVar = IncVar;
24802478 if (isa(ARStart) && isa(IVCount)) {
24812479 const APInt &Start = cast(ARStart)->getAPInt();
24822480 APInt Count = cast(IVCount)->getAPInt();
2483 // Note that the post-inc value of BackedgeTakenCount may have overflowed
2481 // Note that the post-inc value of ExitCount may have overflowed
24842482 // above such that IVCount is now zero.
2485 if (IVCount != BackedgeTakenCount && Count == 0) {
2483 if (IVCount != ExitCount && Count == 0) {
24862484 Count = APInt::getMaxValue(Count.getBitWidth()).zext(CmpIndVarSize);
24872485 ++Count;
24882486 }
27092707 if (!needsLFTR(L, ExitingBB))
27102708 continue;
27112709
2712 const SCEV *BETakenCount = SE->getExitCount(L, ExitingBB);
2713 if (isa(BETakenCount))
2710 const SCEV *ExitCount = SE->getExitCount(L, ExitingBB);
2711 if (isa(ExitCount))
27142712 continue;
27152713
27162714 // Better to fold to true (TODO: do so!)
2717 if (BETakenCount->isZero())
2715 if (ExitCount->isZero())
27182716 continue;
27192717
2720 PHINode *IndVar = FindLoopCounter(L, ExitingBB, BETakenCount, SE, DT);
2718 PHINode *IndVar = FindLoopCounter(L, ExitingBB, ExitCount, SE, DT);
27212719 if (!IndVar)
27222720 continue;
27232721
27242722 // Avoid high cost expansions. Note: This heuristic is questionable in
27252723 // that our definition of "high cost" is not exactly principled.
2726 if (Rewriter.isHighCostExpansion(BETakenCount, L))
2724 if (Rewriter.isHighCostExpansion(ExitCount, L))
27272725 continue;
27282726
27292727 // Check preconditions for proper SCEVExpander operation. SCEV does not
27352733 //
27362734 // FIXME: SCEV expansion has no way to bail out, so the caller must
27372735 // explicitly check any assumptions made by SCEV. Brittle.
2738 const SCEVAddRecExpr *AR = dyn_cast(BETakenCount);
2736 const SCEVAddRecExpr *AR = dyn_cast(ExitCount);
27392737 if (!AR || AR->getLoop()->getLoopPreheader())
2740 Changed |= linearFunctionTestReplace(L, ExitingBB,
2741 BETakenCount, IndVar,
2738 Changed |= linearFunctionTestReplace(L, ExitingBB, ExitCount, IndVar,
27422739 Rewriter);
27432740 }
27442741 }