Repository navigation
JIT: add fgRemoveUnreachableTry phase - #129655
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 <[email protected]>
|
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. |
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 <[email protected]>
EgorBo
left a comment
There was a problem hiding this comment.
I assume this is needed for WASM correctness? Othwerwise having a new pass with DFS compute call for a few contexts sounds a bit too much
Yes, Wasm control flow has a hard time figuring out what to do with an unreachable try, and it has to figure something out or else it can't emit valid Wasm. Easiest thing is to try and ensure it never happens. I may be able to fix this in the control flow phase, in time. |
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. --------- Co-authored-by: Copilot <[email protected]>
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.