From 6a4f5e2addbddf32c54329d4e91aa830cd204e0f Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 16 Oct 2018 07:50:14 +0000 Subject: [NFC] Move block throw check inside allLoopPathsLeadToBlock llvm-svn: 344588 --- llvm/lib/Analysis/MustExecute.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Analysis/MustExecute.cpp') diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index 7c1ce86d15b..7f0912de26b 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -26,6 +26,11 @@ bool LoopSafetyInfo::headerMayThrow() const { return HeaderMayThrow; } +bool LoopSafetyInfo::blockMayThrow(const BasicBlock *BB) const { + (void)BB; + return anyBlockMayThrow(); +} + bool LoopSafetyInfo::anyBlockMayThrow() const { return MayThrow; } @@ -148,7 +153,10 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, // 3) Exit blocks which are not taken on 1st iteration. // Memoize blocks we've already checked. SmallPtrSet CheckedSuccessors; - for (auto *Pred : Predecessors) + for (auto *Pred : Predecessors) { + // Predecessor block may throw, so it has a side exit. + if (blockMayThrow(Pred)) + return false; for (auto *Succ : successors(Pred)) if (CheckedSuccessors.insert(Succ).second && Succ != BB && !Predecessors.count(Succ)) @@ -169,6 +177,7 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, if (CurLoop->contains(Succ) || !CanProveNotTakenFirstIteration(Succ, DT, CurLoop)) return false; + } // All predecessors can only lead us to BB. return true; @@ -194,11 +203,6 @@ bool LoopSafetyInfo::isGuaranteedToExecute(const Instruction &Inst, return !headerMayThrow() || Inst.getParent()->getFirstNonPHIOrDbg() == &Inst; - // Somewhere in this loop there is an instruction which may throw and make us - // exit the loop. - if (anyBlockMayThrow()) - return false; - // If there is a path from header to exit or latch that doesn't lead to our // instruction's block, return false. if (!allLoopPathsLeadToBlock(CurLoop, Inst.getParent(), DT)) -- cgit v1.2.3