[IndVarSimplify] Cleanup spaces and reduce variable scope [NFCI]

Minor clean-ups + clang-format.
This commit is contained in:
Alina Sbirlea 2020-01-22 15:26:12 -08:00
parent 6baf31b7c1
commit b5b6126d97
1 changed files with 37 additions and 39 deletions

View File

@ -2344,8 +2344,7 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
L->getExitingBlocks(ExitingBlocks); L->getExitingBlocks(ExitingBlocks);
// Remove all exits which aren't both rewriteable and analyzeable. // Remove all exits which aren't both rewriteable and analyzeable.
auto NewEnd = llvm::remove_if(ExitingBlocks, auto NewEnd = llvm::remove_if(ExitingBlocks, [&](BasicBlock *ExitingBB) {
[&](BasicBlock *ExitingBB) {
// If our exitting block exits multiple loops, we can only rewrite the // If our exitting block exits multiple loops, we can only rewrite the
// innermost one. Otherwise, we're changing how many times the innermost // innermost one. Otherwise, we're changing how many times the innermost
// loop runs before it exits. // loop runs before it exits.
@ -2468,8 +2467,6 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
SmallVector<BasicBlock*, 16> ExitingBlocks; SmallVector<BasicBlock*, 16> ExitingBlocks;
L->getExitingBlocks(ExitingBlocks); L->getExitingBlocks(ExitingBlocks);
bool Changed = false;
// Finally, see if we can rewrite our exit conditions into a loop invariant // Finally, see if we can rewrite our exit conditions into a loop invariant
// form. If we have a read-only loop, and we can tell that we must exit down // form. If we have a read-only loop, and we can tell that we must exit down
// a path which does not need any of the values computed within the loop, we // a path which does not need any of the values computed within the loop, we
@ -2480,10 +2477,10 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
// elimination, but restricted to read-only loops and without neccesssarily // elimination, but restricted to read-only loops and without neccesssarily
// needing to kill the loop entirely. // needing to kill the loop entirely.
if (!LoopPredication) if (!LoopPredication)
return Changed; return false;
if (!SE->hasLoopInvariantBackedgeTakenCount(L)) if (!SE->hasLoopInvariantBackedgeTakenCount(L))
return Changed; return false;
// Note: ExactBTC is the exact backedge taken count *iff* the loop exits // Note: ExactBTC is the exact backedge taken count *iff* the loop exits
// through *explicit* control flow. We have to eliminate the possibility of // through *explicit* control flow. We have to eliminate the possibility of
@ -2492,11 +2489,11 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
if (isa<SCEVCouldNotCompute>(ExactBTC) || if (isa<SCEVCouldNotCompute>(ExactBTC) ||
!SE->isLoopInvariant(ExactBTC, L) || !SE->isLoopInvariant(ExactBTC, L) ||
!isSafeToExpand(ExactBTC, *SE)) !isSafeToExpand(ExactBTC, *SE))
return Changed; return false;
// If we end up with a pointer exit count, bail. It may be unsized. // If we end up with a pointer exit count, bail. It may be unsized.
if (!ExactBTC->getType()->isIntegerTy()) if (!ExactBTC->getType()->isIntegerTy())
return Changed; return false;
auto BadExit = [&](BasicBlock *ExitingBB) { auto BadExit = [&](BasicBlock *ExitingBB) {
// If our exiting block exits multiple loops, we can only rewrite the // If our exiting block exits multiple loops, we can only rewrite the
@ -2556,7 +2553,7 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
// is complicated and we choose not to for now. // is complicated and we choose not to for now.
for (unsigned i = 1; i < ExitingBlocks.size(); i++) for (unsigned i = 1; i < ExitingBlocks.size(); i++)
if (!DT->dominates(ExitingBlocks[i-1], ExitingBlocks[i])) if (!DT->dominates(ExitingBlocks[i-1], ExitingBlocks[i]))
return Changed; return false;
// Given our sorted total order, we know that exit[j] must be evaluated // Given our sorted total order, we know that exit[j] must be evaluated
// after all exit[i] such j > i. // after all exit[i] such j > i.
@ -2567,7 +2564,7 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
} }
if (ExitingBlocks.empty()) if (ExitingBlocks.empty())
return Changed; return false;
// We rely on not being able to reach an exiting block on a later iteration // We rely on not being able to reach an exiting block on a later iteration
// then it's statically compute exit count. The implementaton of // then it's statically compute exit count. The implementaton of
@ -2589,8 +2586,9 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
for (auto &I : *BB) for (auto &I : *BB)
// TODO:isGuaranteedToTransfer // TODO:isGuaranteedToTransfer
if (I.mayHaveSideEffects() || I.mayThrow()) if (I.mayHaveSideEffects() || I.mayThrow())
return Changed; return false;
bool Changed = false;
// Finally, do the actual predication for all predicatable blocks. A couple // Finally, do the actual predication for all predicatable blocks. A couple
// of notes here: // of notes here:
// 1) We don't bother to constant fold dominated exits with identical exit // 1) We don't bother to constant fold dominated exits with identical exit
@ -2644,7 +2642,6 @@ bool IndVarSimplify::run(Loop *L) {
// We need (and expect!) the incoming loop to be in LCSSA. // We need (and expect!) the incoming loop to be in LCSSA.
assert(L->isRecursivelyLCSSAForm(*DT, *LI) && assert(L->isRecursivelyLCSSAForm(*DT, *LI) &&
"LCSSA required to run indvars!"); "LCSSA required to run indvars!");
bool Changed = false;
// If LoopSimplify form is not available, stay out of trouble. Some notes: // If LoopSimplify form is not available, stay out of trouble. Some notes:
// - LSR currently only supports LoopSimplify-form loops. Indvars' // - LSR currently only supports LoopSimplify-form loops. Indvars'
@ -2663,6 +2660,7 @@ bool IndVarSimplify::run(Loop *L) {
const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L); const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L);
#endif #endif
bool Changed = false;
// If there are any floating-point recurrences, attempt to // If there are any floating-point recurrences, attempt to
// transform them to use integer recurrences. // transform them to use integer recurrences.
Changed |= rewriteNonIntegerIVs(L); Changed |= rewriteNonIntegerIVs(L);