Skip to content

Commit 918d779

Browse files
committed
[IndVars] Factor out a helper function for readability [NFC]
llvm-svn: 375133
1 parent 00bbe99 commit 918d779

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,31 +2646,44 @@ bool IndVarSimplify::sinkUnusedInvariants(Loop *L) {
26462646
return MadeAnyChanges;
26472647
}
26482648

2649-
bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
2649+
/// Return a symbolic upper bound for the backedge taken count of the loop.
2650+
/// This is more general than getConstantMaxBackedgeTakenCount as it returns
2651+
/// an arbitrary expression as opposed to only constants.
2652+
/// TODO: Move into the ScalarEvolution class.
2653+
static const SCEV* getMaxBackedgeTakenCount(ScalarEvolution &SE,
2654+
DominatorTree &DT, Loop *L) {
26502655
SmallVector<BasicBlock*, 16> ExitingBlocks;
26512656
L->getExitingBlocks(ExitingBlocks);
26522657

26532658
// Form an expression for the maximum exit count possible for this loop. We
26542659
// merge the max and exact information to approximate a version of
26552660
// getConstantMaxBackedgeTakenCount which isn't restricted to just constants.
2656-
// TODO: factor this out as a version of getConstantMaxBackedgeTakenCount which
2657-
// isn't guaranteed to return a constant.
26582661
SmallVector<const SCEV*, 4> ExitCounts;
2659-
const SCEV *MaxConstEC = SE->getConstantMaxBackedgeTakenCount(L);
2662+
const SCEV *MaxConstEC = SE.getConstantMaxBackedgeTakenCount(L);
26602663
if (!isa<SCEVCouldNotCompute>(MaxConstEC))
26612664
ExitCounts.push_back(MaxConstEC);
26622665
for (BasicBlock *ExitingBB : ExitingBlocks) {
2663-
const SCEV *ExitCount = SE->getExitCount(L, ExitingBB);
2666+
const SCEV *ExitCount = SE.getExitCount(L, ExitingBB);
26642667
if (!isa<SCEVCouldNotCompute>(ExitCount)) {
2665-
assert(DT->dominates(ExitingBB, L->getLoopLatch()) &&
2668+
assert(DT.dominates(ExitingBB, L->getLoopLatch()) &&
26662669
"We should only have known counts for exiting blocks that "
26672670
"dominate latch!");
26682671
ExitCounts.push_back(ExitCount);
26692672
}
26702673
}
26712674
if (ExitCounts.empty())
2675+
return SE.getCouldNotCompute();
2676+
return SE.getUMinFromMismatchedTypes(ExitCounts);
2677+
}
2678+
2679+
bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
2680+
SmallVector<BasicBlock*, 16> ExitingBlocks;
2681+
L->getExitingBlocks(ExitingBlocks);
2682+
2683+
// Get a symbolic upper bound on the loop backedge taken count.
2684+
const SCEV *MaxExitCount = getMaxBackedgeTakenCount(*SE, *DT, L);
2685+
if (isa<SCEVCouldNotCompute>(MaxExitCount))
26722686
return false;
2673-
const SCEV *MaxExitCount = SE->getUMinFromMismatchedTypes(ExitCounts);
26742687

26752688
bool Changed = false;
26762689
for (BasicBlock *ExitingBB : ExitingBlocks) {

0 commit comments

Comments
 (0)