[llvm] LoopDeletion: Move EH pad check before the isLoopNeverExecuted Check (PR #78189)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 15 08:48:42 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Manish Kausik H (Nirhar)
<details>
<summary>Changes</summary>
This commit modifies `LoopDeletion::deleteLoopIfDead` to check if the exit block of a loop is an EH pad before checking if the loop gets executed. This handles the case where an unreacheable loop has a landingpad as an Exit block, and the loop gets deleted, leaving leaving the landingpad without an edge from an unwind clause.
Fixes #<!-- -->76852
---
Full diff: https://github.com/llvm/llvm-project/pull/78189.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/LoopDeletion.cpp (+7-7)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
index c041e3621a16bd..bfe9374cf2f8c8 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -452,6 +452,13 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT,
BasicBlock *ExitBlock = L->getUniqueExitBlock();
+ // We can't directly branch to an EH pad. Don't bother handling this edge
+ // case.
+ if (ExitBlock && ExitBlock->isEHPad()) {
+ LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n");
+ return LoopDeletionResult::Unmodified;
+ }
+
if (ExitBlock && isLoopNeverExecuted(L)) {
LLVM_DEBUG(dbgs() << "Loop is proven to never execute, delete it!\n");
// We need to forget the loop before setting the incoming values of the exit
@@ -487,13 +494,6 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT,
return LoopDeletionResult::Unmodified;
}
- // We can't directly branch to an EH pad. Don't bother handling this edge
- // case.
- if (ExitBlock && ExitBlock->isEHPad()) {
- LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n");
- return LoopDeletionResult::Unmodified;
- }
-
// Finally, we have to check that the loop really is dead.
bool Changed = false;
if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader, LI)) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/78189
More information about the llvm-commits
mailing list