diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h --- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h +++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h @@ -513,8 +513,8 @@ /// If the branch condition of the header is partially invariant, return a pair /// containing the instructions to duplicate and a boolean Constant to update /// the condition in the loops created for the true or false successors. -Optional hasPartialIVCondition(Loop *L, unsigned MSSAThreshold, - MemorySSA *MSSA, AAResults *AA); +Optional hasPartialIVCondition(Loop &L, unsigned MSSAThreshold, + MemorySSA &MSSA, AAResults &AA); } // end namespace llvm diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -848,7 +848,7 @@ if (MSSA && !findOptionMDForLoop(CurrentLoop, "llvm.loop.unswitch.partial.disable")) { if (auto Info = - llvm::hasPartialIVCondition(CurrentLoop, MSSAThreshold, MSSA, AA)) { + hasPartialIVCondition(*CurrentLoop, MSSAThreshold, *MSSA, *AA)) { assert(!Info->InstToDuplicate.empty() && "need at least a partially invariant condition"); LLVM_DEBUG(dbgs() << "loop-unswitch: Found partially invariant condition " diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1706,29 +1706,18 @@ return std::make_pair(FirstInst, Check); } -/// Check if the loop header has a conditional branch that is not -/// loop-invariant, because it involves load instructions. If all paths from -/// either the true or false successor to the header or loop exists do not -/// modify the memory feeding the condition, perform 'partial unswitching'. That -/// is, duplicate the instructions feeding the condition in the pre-header. Then -/// unswitch on the duplicated condition. The condition is now known in the -/// unswitched version for the 'invariant' path through the original loop. -/// -/// If the branch condition of the header is partially invariant, return a pair -/// containing the instructions to duplicate and a boolean Constant to update -/// the condition in the loops created for the true or false successors. -Optional llvm::hasPartialIVCondition(Loop *L, +Optional llvm::hasPartialIVCondition(Loop &L, unsigned MSSAThreshold, - MemorySSA *MSSA, - AAResults *AA) { - auto *TI = dyn_cast(L->getHeader()->getTerminator()); + MemorySSA &MSSA, + AAResults &AA) { + auto *TI = dyn_cast(L.getHeader()->getTerminator()); if (!TI || !TI->isConditional()) return {}; auto *CondI = dyn_cast(TI->getCondition()); // The case with the condition outside the loop should already be handled // earlier. - if (!CondI || !L->contains(CondI)) + if (!CondI || !L.contains(CondI)) return {}; SmallVector InstToDuplicate; @@ -1741,7 +1730,7 @@ SmallVector AccessedLocs; while (!WorkList.empty()) { Instruction *I = dyn_cast(WorkList.pop_back_val()); - if (!I || !L->contains(I)) + if (!I || !L.contains(I)) continue; // TODO: support additional instructions. @@ -1754,7 +1743,7 @@ return {}; InstToDuplicate.push_back(I); - if (MemoryAccess *MA = MSSA->getMemoryAccess(I)) { + if (MemoryAccess *MA = MSSA.getMemoryAccess(I)) { if (auto *MemUse = dyn_cast_or_null(MA)) { // Queue the defining access to check for alias checks. AccessesToCheck.push_back(MemUse->getDefiningAccess()); @@ -1772,9 +1761,9 @@ return {}; SmallVector ExitingBlocks; - L->getExitingBlocks(ExitingBlocks); + L.getExitingBlocks(ExitingBlocks); auto HasNoClobbersOnPath = - [L, AA, &AccessedLocs, &ExitingBlocks, &InstToDuplicate, + [&L, &AA, &AccessedLocs, &ExitingBlocks, &InstToDuplicate, MSSAThreshold](BasicBlock *Succ, BasicBlock *Header, SmallVector AccessesToCheck) -> Optional { @@ -1791,7 +1780,7 @@ while (!WorkList.empty()) { BasicBlock *Current = WorkList.pop_back_val(); - if (!L->contains(Current)) + if (!L.contains(Current)) continue; const auto &SeenIns = Seen.insert(Current); if (!SeenIns.second) @@ -1829,9 +1818,9 @@ // For a MemoryDef, check if is aliases any of the location feeding // the original condition. if (auto *CurrentDef = dyn_cast(Current)) { - if (any_of(AccessedLocs, [AA, CurrentDef](MemoryLocation &Loc) { + if (any_of(AccessedLocs, [&AA, CurrentDef](MemoryLocation &Loc) { return isModSet( - AA->getModRefInfo(CurrentDef->getMemoryInst(), Loc)); + AA.getModRefInfo(CurrentDef->getMemoryInst(), Loc)); })) return {}; } @@ -1843,7 +1832,7 @@ // We could also allow loops with known trip counts without mustprogress, // but ScalarEvolution may not be available. Info.PathIsNoop &= - L->getHeader()->getParent()->mustProgress() || hasMustProgress(L); + L.getHeader()->getParent()->mustProgress() || hasMustProgress(&L); // If the path is considered a no-op so far, check if it reaches a // single exit block without any phis. This ensures no values from the @@ -1853,7 +1842,7 @@ if (!Seen.contains(Exiting)) continue; for (auto *Succ : successors(Exiting)) { - if (L->contains(Succ)) + if (L.contains(Succ)) continue; Info.PathIsNoop &= llvm::empty(Succ->phis()) && @@ -1878,12 +1867,12 @@ if (TI->getSuccessor(0) == TI->getSuccessor(1)) return {}; - if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(0), L->getHeader(), + if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(0), L.getHeader(), AccessesToCheck)) { Info->KnownValue = ConstantInt::getTrue(TI->getContext()); return Info; } - if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(1), L->getHeader(), + if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(1), L.getHeader(), AccessesToCheck)) { Info->KnownValue = ConstantInt::getFalse(TI->getContext()); return Info;