-
Notifications
You must be signed in to change notification settings - Fork 14.3k
LoopDeletion: Move EH pad check before the isLoopNeverExecuted Check #78189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@nikic Have a look at these changes, thanks! |
@llvm/pr-subscribers-llvm-transforms Author: Manish Kausik H (Nirhar) ChangesThis commit modifies Fixes #76852 Full diff: https://github.com/llvm/llvm-project/pull/78189.diff 1 Files Affected:
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)) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a test case in llvm/test/Transforms/LoopDeletion.
98a6318
to
4d8faa9
Compare
@nikic Have a look at the added test , thanks! |
llvm/test/Transforms/LoopDeletion/loop-with-ehpad-not-executed.ll
Outdated
Show resolved
Hide resolved
llvm/test/Transforms/LoopDeletion/loop-with-ehpad-not-executed.ll
Outdated
Show resolved
Hide resolved
llvm/test/Transforms/LoopDeletion/loop-with-ehpad-not-executed.ll
Outdated
Show resolved
Hide resolved
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 llvm#76852
4d8faa9
to
c2f5d0b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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