Skip to content

JIT: add fgRemoveUnreachableTry phase#129655

Open
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:jit-remove-unreachable-try
Open

JIT: add fgRemoveUnreachableTry phase#129655
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:jit-remove-unreachable-try

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Jun 20, 2026

Copy link
Copy Markdown
Member

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.

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>
Copilot AI review requested due to automatic review settings June 20, 2026 14:05
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 20, 2026
@AndyAyersMS

Copy link
Copy Markdown
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
fyi @dotnet/jit-contrib

Only impacts two methods in SPMI. Needed for Wasm.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fgRemoveUnreachableTry and 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 callfinally pairs 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.

Comment thread src/coreclr/jit/fgehopt.cpp Outdated
Comment thread src/coreclr/jit/compiler.cpp
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>
@AndyAyersMS AndyAyersMS requested a review from EgorBo June 21, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants