aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/MustExecute.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/Analysis/MustExecute.cpp
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'llvm/lib/Analysis/MustExecute.cpp')
-rw-r--r--llvm/lib/Analysis/MustExecute.cpp26
1 files changed, 18 insertions, 8 deletions
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<const BasicBlock *, 4> 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 <typename K, typename V, typename FnTy, typename... ArgsTy>
-static V getOrCreateCachedOptional(K Key, DenseMap<K, Optional<V>> &Map,
- FnTy &&Fn, ArgsTy&&... args) {
- Optional<V> &OptVal = Map[Key];
+static V getOrCreateCachedOptional(K Key, DenseMap<K, std::optional<V>> &Map,
+ FnTy &&Fn, ArgsTy &&...args) {
+ std::optional<V> &OptVal = Map[Key];
if (!OptVal)
OptVal = Fn(std::forward<ArgsTy>(args)...);
- return OptVal.value();
+ return *OptVal;
}
const BasicBlock *