JIT: add fgRemoveUnreachableTry phase#129655
Open
AndyAyersMS wants to merge 2 commits into
Open
Conversation
Removes EH regions whose try entry has become unreachable. Run after each empty-EH-cleanup pass. Fixes an issue for wasm control flow, which is not tolerant of unreachable EH. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
This only runs once, in the last group of EH cleanups. Not needed if not optimizing, as unreachable trys are removed at the end of importation, and the other trys then remain reachable. @EgorBo PTAL Only impacts two methods in SPMI. Needed for Wasm. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new JIT phase that detects EH clauses whose try entry block is no longer reachable from method entry and removes those EH regions (including associated dead blocks), to avoid carrying unreachable EH into later compilation stages.
Changes:
- Add a new flowgraph/EH cleanup phase
fgRemoveUnreachableTryand wire it into the main compilation pipeline. - Add a new phase ID (
PHASE_REMOVE_UNREACHABLE_TRY) and a DEBUG-only config knob (JitEnableRemoveUnreachableTry) consistent with existing EH cleanup toggles. - Implement logic to retarget
callfinallypairs for dead finally handlers, remove EH table entries, rebuild DFS, and delete newly-unreachable blocks.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/jitconfigvalues.h | Adds JitEnableRemoveUnreachableTry config switch (DEBUG override pattern). |
| src/coreclr/jit/fgehopt.cpp | Implements Compiler::fgRemoveUnreachableTry EH cleanup logic. |
| src/coreclr/jit/compphases.h | Adds PHASE_REMOVE_UNREACHABLE_TRY phase name. |
| src/coreclr/jit/compiler.h | Declares fgRemoveUnreachableTry on Compiler. |
| src/coreclr/jit/compiler.cpp | Invokes the new phase once before funclet creation. |
Update the Notes section to describe the actual PASS ordering: EH table entries are dropped first, then the DFS is rebuilt and blocks are removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes EH regions whose try entry has become unreachable. Runs once, in the last set of EH cleanup passes (just before funclet creation). Not needed if not optimizing, as unreachable trys are removed at the end of importation and the other trys then remain reachable. Fixes an issue for wasm control flow, which is not tolerant of unreachable EH.
Note
This PR description was edited with assistance from GitHub Copilot.