3737#include " llvm/Transforms/Utils/BasicBlockUtils.h"
3838#include " llvm/Transforms/Utils/Cloning.h"
3939#include " llvm/Transforms/Utils/Local.h"
40- #include " llvm/Transforms/Utils/LoopRotationUtils.h"
4140#include " llvm/Transforms/Utils/LoopUtils.h"
4241#include " llvm/Transforms/Utils/ScalarEvolutionExpander.h"
4342#include " llvm/Transforms/Utils/UnrollLoop.h"
@@ -575,46 +574,22 @@ static Value *CreateTripRemainder(IRBuilder<> &B, Value *BECount,
575574// / if (extraiters != 0) jump Epil: // Omitted if unroll factor is 2.
576575// / EpilExit:
577576
578- LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder (
577+ bool llvm::UnrollRuntimeLoopRemainder (
579578 Loop *L, unsigned Count, bool AllowExpensiveTripCount,
580579 bool UseEpilogRemainder, bool UnrollRemainder, bool ForgetAllSCEV,
581580 LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC,
582581 const TargetTransformInfo *TTI, bool PreserveLCSSA,
583582 unsigned SCEVExpansionBudget, bool RuntimeUnrollMultiExit,
584- bool AllowLoopRotation, Loop **ResultLoop) {
583+ Loop **ResultLoop) {
585584 LLVM_DEBUG (dbgs () << " Trying runtime unrolling on Loop: \n " );
586585 LLVM_DEBUG (L->dump ());
587586 LLVM_DEBUG (UseEpilogRemainder ? dbgs () << " Using epilog remainder.\n "
588587 : dbgs () << " Using prolog remainder.\n " );
589588
590- LoopReminderUnrollResult Result = LoopReminderUnrollResult::Unmodified;
591-
592- // Rotate loop if it makes the exit count from the latch computable.
593- if (AllowLoopRotation) {
594- BasicBlock *OrigHeader = L->getHeader ();
595- BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator ());
596- if (BI && !BI->isUnconditional () &&
597- isa<SCEVCouldNotCompute>(SE->getExitCount (L, L->getLoopLatch ())) &&
598- !isa<SCEVCouldNotCompute>(SE->getExitCount (L, OrigHeader))) {
599- LLVM_DEBUG (
600- dbgs () << " Rotating loop to make the exit count computable.\n " );
601- SimplifyQuery SQ{OrigHeader->getDataLayout ()};
602- SQ.TLI = nullptr ;
603- SQ.DT = DT;
604- SQ.AC = AC;
605- if (llvm::LoopRotation (L, LI, TTI, AC, DT, SE,
606- /* MemorySSAUpdater*/ nullptr , SQ,
607- /* RotationOnly*/ false , /* Threshold*/ 16 ,
608- /* IsUtilMode*/ false , /* PrepareForLTO*/ false ,
609- [](Loop *, ScalarEvolution *) { return true ; }))
610- Result = LoopReminderUnrollResult::Rotated;
611- }
612- }
613-
614589 // Make sure the loop is in canonical form.
615590 if (!L->isLoopSimplifyForm ()) {
616591 LLVM_DEBUG (dbgs () << " Not in simplify form!\n " );
617- return Result ;
592+ return false ;
618593 }
619594
620595 // Guaranteed by LoopSimplifyForm.
@@ -628,7 +603,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
628603 LLVM_DEBUG (
629604 dbgs ()
630605 << " Loop latch not terminated by a conditional branch.\n " );
631- return Result ;
606+ return false ;
632607 }
633608
634609 unsigned ExitIndex = LatchBR->getSuccessor (0 ) == Header ? 1 : 0 ;
@@ -640,7 +615,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
640615 LLVM_DEBUG (
641616 dbgs ()
642617 << " One of the loop latch successors must be the exit block.\n " );
643- return Result ;
618+ return false ;
644619 }
645620
646621 // These are exit blocks other than the target of the latch exiting block.
@@ -652,12 +627,12 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
652627 // We rely on LCSSA form being preserved when the exit blocks are transformed.
653628 // (Note that only an off-by-default mode of the old PM disables PreserveLCCA.)
654629 if (!PreserveLCSSA)
655- return Result ;
630+ return false ;
656631
657632 // Priority goes to UnrollRuntimeMultiExit if it's supplied.
658633 if (UnrollRuntimeMultiExit.getNumOccurrences ()) {
659634 if (!UnrollRuntimeMultiExit)
660- return Result ;
635+ return false ;
661636 } else {
662637 // Otherwise perform multi-exit unrolling, if either the target indicates
663638 // it is profitable or the general profitability heuristics apply.
@@ -666,14 +641,14 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
666641 UseEpilogRemainder)) {
667642 LLVM_DEBUG (dbgs () << " Multiple exit/exiting blocks in loop and "
668643 " multi-exit unrolling not enabled!\n " );
669- return Result ;
644+ return false ;
670645 }
671646 }
672647 }
673648 // Use Scalar Evolution to compute the trip count. This allows more loops to
674649 // be unrolled than relying on induction var simplification.
675650 if (!SE)
676- return Result ;
651+ return false ;
677652
678653 // Only unroll loops with a computable trip count.
679654 // We calculate the backedge count by using getExitCount on the Latch block,
@@ -683,7 +658,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
683658 const SCEV *BECountSC = SE->getExitCount (L, Latch);
684659 if (isa<SCEVCouldNotCompute>(BECountSC)) {
685660 LLVM_DEBUG (dbgs () << " Could not compute exit block SCEV\n " );
686- return Result ;
661+ return false ;
687662 }
688663
689664 unsigned BEWidth = cast<IntegerType>(BECountSC->getType ())->getBitWidth ();
@@ -694,7 +669,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
694669 SE->getAddExpr (BECountSC, SE->getConstant (BECountSC->getType (), 1 ));
695670 if (isa<SCEVCouldNotCompute>(TripCountSC)) {
696671 LLVM_DEBUG (dbgs () << " Could not compute trip count SCEV.\n " );
697- return Result ;
672+ return false ;
698673 }
699674
700675 BasicBlock *PreHeader = L->getLoopPreheader ();
@@ -705,7 +680,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
705680 Expander.isHighCostExpansion (TripCountSC, L, SCEVExpansionBudget, TTI,
706681 PreHeaderBR)) {
707682 LLVM_DEBUG (dbgs () << " High cost for expanding trip count scev!\n " );
708- return Result ;
683+ return false ;
709684 }
710685
711686 // This constraint lets us deal with an overflowing trip count easily; see the
@@ -714,7 +689,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
714689 LLVM_DEBUG (
715690 dbgs ()
716691 << " Count failed constraint on overflow trip count calculation.\n " );
717- return Result ;
692+ return false ;
718693 }
719694
720695 // Loop structure is the following:
@@ -1060,5 +1035,5 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
10601035 if (ResultLoop && UnrollResult != LoopUnrollResult::FullyUnrolled)
10611036 *ResultLoop = remainderLoop;
10621037 NumRuntimeUnrolled++;
1063- return LoopReminderUnrollResult::Unrolled ;
1038+ return true ;
10641039}
0 commit comments