From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- llvm/lib/Analysis/MustExecute.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Analysis/MustExecute.cpp') diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index ac6590c1d8a2..2f68996e1c60 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -59,10 +59,11 @@ void SimpleLoopSafetyInfo::computeLoopSafetyInfo(const Loop *CurLoop) { // The first block in loopinfo.Blocks is guaranteed to be the header. assert(Header == *CurLoop->getBlocks().begin() && "First block must be header"); - for (Loop::block_iterator BB = std::next(CurLoop->block_begin()), - BBE = CurLoop->block_end(); - (BB != BBE) && !MayThrow; ++BB) - MayThrow |= !isGuaranteedToTransferExecutionToSuccessor(*BB); + for (const BasicBlock *BB : llvm::drop_begin(CurLoop->blocks())) { + MayThrow |= !isGuaranteedToTransferExecutionToSuccessor(BB); + if (MayThrow) + break; + } computeBlockColors(CurLoop); } @@ -200,6 +201,15 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, SmallPtrSet Predecessors; collectTransitivePredecessors(CurLoop, BB, Predecessors); + // Bail out if a latch block is part of the predecessor set. In this case + // we may take the backedge to the header and not execute other latch + // successors. + for (const BasicBlock *Pred : predecessors(CurLoop->getHeader())) + // Predecessors only contains loop blocks, so we don't have to worry about + // preheader predecessors here. + if (Predecessors.contains(Pred)) + return false; + // Make sure that all successors of, all predecessors of BB which are not // dominated by BB, are either: // 1) BB, @@ -488,12 +498,12 @@ bool llvm::mayContainIrreducibleControl(const Function &F, const LoopInfo *LI) { /// Lookup \p Key in \p Map and return the result, potentially after /// initializing the optional through \p Fn(\p args). template -static V getOrCreateCachedOptional(K Key, DenseMap> &Map, - FnTy &&Fn, ArgsTy&&... args) { - Optional &OptVal = Map[Key]; +static V getOrCreateCachedOptional(K Key, DenseMap> &Map, + FnTy &&Fn, ArgsTy &&...args) { + std::optional &OptVal = Map[Key]; if (!OptVal) OptVal = Fn(std::forward(args)...); - return OptVal.value(); + return *OptVal; } const BasicBlock * -- cgit v1.2.3