diff options
author | Philip Reames <listmail@philipreames.com> | 2019-10-17 16:55:34 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-10-17 16:55:34 +0000 |
commit | 918d779d901c4ba0b7236628e98c147543a8854b (patch) | |
tree | 49c46bdc960838e4ad888716668d0c20fa74f030 | |
parent | 00bbe990c5d4472d5413479a539b3d6edbb3ca7a (diff) | |
download | bcm5719-llvm-918d779d901c4ba0b7236628e98c147543a8854b.tar.gz bcm5719-llvm-918d779d901c4ba0b7236628e98c147543a8854b.zip |
[IndVars] Factor out a helper function for readability [NFC]
llvm-svn: 375133
-rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 2fb8d702dcb..dc0a1dadb3e 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -2646,31 +2646,44 @@ bool IndVarSimplify::sinkUnusedInvariants(Loop *L) { return MadeAnyChanges; } -bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) { +/// Return a symbolic upper bound for the backedge taken count of the loop. +/// This is more general than getConstantMaxBackedgeTakenCount as it returns +/// an arbitrary expression as opposed to only constants. +/// TODO: Move into the ScalarEvolution class. +static const SCEV* getMaxBackedgeTakenCount(ScalarEvolution &SE, + DominatorTree &DT, Loop *L) { SmallVector<BasicBlock*, 16> ExitingBlocks; L->getExitingBlocks(ExitingBlocks); // Form an expression for the maximum exit count possible for this loop. We // merge the max and exact information to approximate a version of // getConstantMaxBackedgeTakenCount which isn't restricted to just constants. - // TODO: factor this out as a version of getConstantMaxBackedgeTakenCount which - // isn't guaranteed to return a constant. SmallVector<const SCEV*, 4> ExitCounts; - const SCEV *MaxConstEC = SE->getConstantMaxBackedgeTakenCount(L); + const SCEV *MaxConstEC = SE.getConstantMaxBackedgeTakenCount(L); if (!isa<SCEVCouldNotCompute>(MaxConstEC)) ExitCounts.push_back(MaxConstEC); for (BasicBlock *ExitingBB : ExitingBlocks) { - const SCEV *ExitCount = SE->getExitCount(L, ExitingBB); + const SCEV *ExitCount = SE.getExitCount(L, ExitingBB); if (!isa<SCEVCouldNotCompute>(ExitCount)) { - assert(DT->dominates(ExitingBB, L->getLoopLatch()) && + assert(DT.dominates(ExitingBB, L->getLoopLatch()) && "We should only have known counts for exiting blocks that " "dominate latch!"); ExitCounts.push_back(ExitCount); } } if (ExitCounts.empty()) + return SE.getCouldNotCompute(); + return SE.getUMinFromMismatchedTypes(ExitCounts); +} + +bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) { + SmallVector<BasicBlock*, 16> ExitingBlocks; + L->getExitingBlocks(ExitingBlocks); + + // Get a symbolic upper bound on the loop backedge taken count. + const SCEV *MaxExitCount = getMaxBackedgeTakenCount(*SE, *DT, L); + if (isa<SCEVCouldNotCompute>(MaxExitCount)) return false; - const SCEV *MaxExitCount = SE->getUMinFromMismatchedTypes(ExitCounts); bool Changed = false; for (BasicBlock *ExitingBB : ExitingBlocks) { |