Revert [LFTR] Rename variable to minimize confusion [NFC]

Reverting because it depends on r363289, which breaks a green dragon
build:
    http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/18208

This reverts r363293 (git commit c37be29634)

llvm-svn: 363425
This commit is contained in:
Florian Hahn 2019-06-14 17:22:49 +00:00
parent 5c7fcbdc4b
commit e1b4b1b46e
1 changed files with 18 additions and 15 deletions

View File

@ -151,7 +151,7 @@ class IndVarSimplify {
bool hasHardUserWithinLoop(const Loop *L, const Instruction *I) const; bool hasHardUserWithinLoop(const Loop *L, const Instruction *I) const;
bool linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, bool linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB,
const SCEV *ExitCount, const SCEV *BackedgeTakenCount,
PHINode *IndVar, SCEVExpander &Rewriter); PHINode *IndVar, SCEVExpander &Rewriter);
bool sinkUnusedInvariants(Loop *L); bool sinkUnusedInvariants(Loop *L);
@ -2382,7 +2382,8 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB,
/// determine a loop-invariant trip count of the loop, which is actually a much /// determine a loop-invariant trip count of the loop, which is actually a much
/// broader range than just linear tests. /// broader range than just linear tests.
bool IndVarSimplify:: bool IndVarSimplify::
linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, const SCEV *ExitCount, linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB,
const SCEV *BackedgeTakenCount,
PHINode *IndVar, SCEVExpander &Rewriter) { PHINode *IndVar, SCEVExpander &Rewriter) {
assert(isLoopCounter(IndVar, L, SE)); assert(isLoopCounter(IndVar, L, SE));
assert(L->getLoopLatch() && "Loop no longer in simplified form?"); assert(L->getLoopLatch() && "Loop no longer in simplified form?");
@ -2391,7 +2392,7 @@ linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, const SCEV *ExitCount,
// Initialize CmpIndVar and IVCount to their preincremented values. // Initialize CmpIndVar and IVCount to their preincremented values.
Value *CmpIndVar = IndVar; Value *CmpIndVar = IndVar;
const SCEV *IVCount = ExitCount; const SCEV *IVCount = BackedgeTakenCount;
// If the exiting block is the same as the backedge block, we prefer to // If the exiting block is the same as the backedge block, we prefer to
// compare against the post-incremented value, otherwise we must compare // compare against the post-incremented value, otherwise we must compare
@ -2411,9 +2412,10 @@ linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, const SCEV *ExitCount,
if (SafeToPostInc) { if (SafeToPostInc) {
// Add one to the "backedge-taken" count to get the trip count. // Add one to the "backedge-taken" count to get the trip count.
// This addition may overflow, which is valid as long as the comparison // This addition may overflow, which is valid as long as the comparison
// is truncated to ExitCount->getType(). // is truncated to BackedgeTakenCount->getType().
IVCount = SE->getAddExpr(ExitCount, SE->getOne(ExitCount->getType())); IVCount = SE->getAddExpr(BackedgeTakenCount,
// The ExitCount expression contains the number of times that the SE->getOne(BackedgeTakenCount->getType()));
// The BackedgeTaken expression contains the number of times that the
// backedge branches to the loop header. This is one less than the // backedge branches to the loop header. This is one less than the
// number of times the loop executes, so use the incremented indvar. // number of times the loop executes, so use the incremented indvar.
CmpIndVar = IncVar; CmpIndVar = IncVar;
@ -2479,9 +2481,9 @@ linearFunctionTestReplace(Loop *L, BasicBlock *ExitingBB, const SCEV *ExitCount,
if (isa<SCEVConstant>(ARStart) && isa<SCEVConstant>(IVCount)) { if (isa<SCEVConstant>(ARStart) && isa<SCEVConstant>(IVCount)) {
const APInt &Start = cast<SCEVConstant>(ARStart)->getAPInt(); const APInt &Start = cast<SCEVConstant>(ARStart)->getAPInt();
APInt Count = cast<SCEVConstant>(IVCount)->getAPInt(); APInt Count = cast<SCEVConstant>(IVCount)->getAPInt();
// Note that the post-inc value of ExitCount may have overflowed // Note that the post-inc value of BackedgeTakenCount may have overflowed
// above such that IVCount is now zero. // above such that IVCount is now zero.
if (IVCount != ExitCount && Count == 0) { if (IVCount != BackedgeTakenCount && Count == 0) {
Count = APInt::getMaxValue(Count.getBitWidth()).zext(CmpIndVarSize); Count = APInt::getMaxValue(Count.getBitWidth()).zext(CmpIndVarSize);
++Count; ++Count;
} }
@ -2708,21 +2710,21 @@ bool IndVarSimplify::run(Loop *L) {
if (!needsLFTR(L, ExitingBB)) if (!needsLFTR(L, ExitingBB))
continue; continue;
const SCEV *ExitCount = SE->getExitCount(L, ExitingBB); const SCEV *BETakenCount = SE->getExitCount(L, ExitingBB);
if (isa<SCEVCouldNotCompute>(ExitCount)) if (isa<SCEVCouldNotCompute>(BETakenCount))
continue; continue;
// Better to fold to true (TODO: do so!) // Better to fold to true (TODO: do so!)
if (ExitCount->isZero()) if (BETakenCount->isZero())
continue; continue;
PHINode *IndVar = FindLoopCounter(L, ExitingBB, ExitCount, SE, DT); PHINode *IndVar = FindLoopCounter(L, ExitingBB, BETakenCount, SE, DT);
if (!IndVar) if (!IndVar)
continue; continue;
// Avoid high cost expansions. Note: This heuristic is questionable in // Avoid high cost expansions. Note: This heuristic is questionable in
// that our definition of "high cost" is not exactly principled. // that our definition of "high cost" is not exactly principled.
if (Rewriter.isHighCostExpansion(ExitCount, L)) if (Rewriter.isHighCostExpansion(BETakenCount, L))
continue; continue;
// Check preconditions for proper SCEVExpander operation. SCEV does not // Check preconditions for proper SCEVExpander operation. SCEV does not
@ -2734,9 +2736,10 @@ bool IndVarSimplify::run(Loop *L) {
// //
// FIXME: SCEV expansion has no way to bail out, so the caller must // FIXME: SCEV expansion has no way to bail out, so the caller must
// explicitly check any assumptions made by SCEV. Brittle. // explicitly check any assumptions made by SCEV. Brittle.
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(ExitCount); const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(BETakenCount);
if (!AR || AR->getLoop()->getLoopPreheader()) if (!AR || AR->getLoop()->getLoopPreheader())
Changed |= linearFunctionTestReplace(L, ExitingBB, ExitCount, IndVar, Changed |= linearFunctionTestReplace(L, ExitingBB,
BETakenCount, IndVar,
Rewriter); Rewriter);
} }
} }