@@ -2646,31 +2646,44 @@ bool IndVarSimplify::sinkUnusedInvariants(Loop *L) {
2646
2646
return MadeAnyChanges;
2647
2647
}
2648
2648
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) {
2650
2655
SmallVector<BasicBlock*, 16 > ExitingBlocks;
2651
2656
L->getExitingBlocks (ExitingBlocks);
2652
2657
2653
2658
// Form an expression for the maximum exit count possible for this loop. We
2654
2659
// merge the max and exact information to approximate a version of
2655
2660
// 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.
2658
2661
SmallVector<const SCEV*, 4 > ExitCounts;
2659
- const SCEV *MaxConstEC = SE-> getConstantMaxBackedgeTakenCount (L);
2662
+ const SCEV *MaxConstEC = SE. getConstantMaxBackedgeTakenCount (L);
2660
2663
if (!isa<SCEVCouldNotCompute>(MaxConstEC))
2661
2664
ExitCounts.push_back (MaxConstEC);
2662
2665
for (BasicBlock *ExitingBB : ExitingBlocks) {
2663
- const SCEV *ExitCount = SE-> getExitCount (L, ExitingBB);
2666
+ const SCEV *ExitCount = SE. getExitCount (L, ExitingBB);
2664
2667
if (!isa<SCEVCouldNotCompute>(ExitCount)) {
2665
- assert (DT-> dominates (ExitingBB, L->getLoopLatch ()) &&
2668
+ assert (DT. dominates (ExitingBB, L->getLoopLatch ()) &&
2666
2669
" We should only have known counts for exiting blocks that "
2667
2670
" dominate latch!" );
2668
2671
ExitCounts.push_back (ExitCount);
2669
2672
}
2670
2673
}
2671
2674
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))
2672
2686
return false ;
2673
- const SCEV *MaxExitCount = SE->getUMinFromMismatchedTypes (ExitCounts);
2674
2687
2675
2688
bool Changed = false ;
2676
2689
for (BasicBlock *ExitingBB : ExitingBlocks) {
0 commit comments