@@ -581,7 +581,7 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
581581 LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC,
582582 const TargetTransformInfo *TTI, bool PreserveLCSSA,
583583 unsigned SCEVExpansionBudget, bool RuntimeUnrollMultiExit,
584- Loop **ResultLoop) {
584+ bool AllowLoopRotation, Loop **ResultLoop) {
585585 LLVM_DEBUG (dbgs () << " Trying runtime unrolling on Loop: \n " );
586586 LLVM_DEBUG (L->dump ());
587587 LLVM_DEBUG (UseEpilogRemainder ? dbgs () << " Using epilog remainder.\n "
@@ -590,22 +590,25 @@ LoopReminderUnrollResult llvm::UnrollRuntimeLoopRemainder(
590590 LoopReminderUnrollResult Result = LoopReminderUnrollResult::Unmodified;
591591
592592 // Rotate loop if it makes the exit count from the latch computable.
593- BasicBlock *OrigHeader = L->getHeader ();
594- BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator ());
595- if (BI && !BI->isUnconditional () &&
596- isa<SCEVCouldNotCompute>(SE->getExitCount (L, L->getLoopLatch ())) &&
597- !isa<SCEVCouldNotCompute>(SE->getExitCount (L, OrigHeader))) {
598- LLVM_DEBUG (
599- dbgs () << " Rotating loop to make the exit count computable.\n " );
600- SimplifyQuery SQ{OrigHeader->getDataLayout ()};
601- SQ.TLI = nullptr ;
602- SQ.DT = DT;
603- SQ.AC = AC;
604- if (llvm::LoopRotation (L, LI, TTI, AC, DT, SE, nullptr /* MemorySSAUpdater*/ ,
605- SQ, false /* RotationOnly*/ , 16 /* Threshold*/ ,
606- false /* IsUtilMode*/ , false /* PrepareForLTO*/ ,
607- [](Loop *, ScalarEvolution *) { return true ; }))
608- Result = LoopReminderUnrollResult::Rotated;
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+ }
609612 }
610613
611614 // Make sure the loop is in canonical form.
0 commit comments