Skip to content

JIT: support SSA-aware PHI jump threading#126812

Merged
AndyAyersMS merged 2 commits intodotnet:mainfrom
AndyAyersMS:RboSimpleSSAUpdates
Apr 13, 2026
Merged

JIT: support SSA-aware PHI jump threading#126812
AndyAyersMS merged 2 commits intodotnet:mainfrom
AndyAyersMS:RboSimpleSSAUpdates

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS commented Apr 12, 2026

Teach redundant branch elimination to keep jump threading through PHI- based blocks when the PHI uses can be fully accounted for in the block and its immediate successors. Rewrite the affected successor SSA/VN uses, keep dominating-block threading conservative, and add focused regression coverage for the new PHI-based cases.

Fixes #126703 (not quite, yet)

Teach redundant branch elimination to keep jump threading through PHI-
based blocks when the PHI uses can be fully accounted for in the block
and its immediate successors. Rewrite the affected successor SSA/VN uses,
keep dominating-block threading conservative, and add focused regression
coverage for the new PHI-based cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 12, 2026 20:29
@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 Apr 12, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 extends CoreCLR JIT redundant branch optimization (jump threading) to support PHI-based threading when PHI definitions have non-local uses, by accounting for those uses within the threaded block and its immediate successors and rewriting successor SSA/VN uses accordingly. It also adds a focused JIT regression test to cover the new PHI-based scenario.

Changes:

  • Add tracking of PHI SSA uses in the candidate block/successors and rewrite successor SSA/VN uses when threading bypasses the PHI block.
  • Refine jump-thread eligibility checking to return a richer classification (including “needs PHI use resolution”).
  • Add a new JIT test case (JumpThreadPhi) to validate the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/jit/redundantbranchopts.cpp Implements PHI-use discovery and successor SSA/VN rewriting; updates jump-thread check flow.
src/coreclr/jit/compiler.h Introduces JumpThreadCheckResult and declares new helper methods for PHI-use analysis/rewriting.
src/coreclr/jit/compmemkind.h Adds a dedicated allocator kind for redundant-branch/jump-threading data.
src/tests/JIT/opt/RedundantBranch/JumpThreadPhi.cs Adds regression coverage for PHI-based jump threading through a PHI-producing pattern.
src/tests/JIT/opt/RedundantBranch/JumpThreadPhi.csproj Adds the test project definition consistent with existing tests in the folder.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

Follow-on to #126711.

If all the uses of a global phi in a jump-threading candidate block are in the block and its successors, we can (in most cases) allow jump threading and rewrite the successor uses to the appropriate new ssa def & vn.

We avoid cases where the successors already have PHIs or would need to have new PHIs. These seem somewhat rare.

@EgorBo PTAL
fyi @dotnet/jit-contrib

Copy link
Copy Markdown
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

Thanks for filing a fix for this!

@AndyAyersMS
Copy link
Copy Markdown
Member Author

Thanks for filing a fix for this!

There are a couple of follow-ons coming that should let us actually fix #126703, but I think this is a good improvement on its own.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

Diffs

Linux x64 is probably most representative, other os/arch seem to be missing some collections.

@AndyAyersMS AndyAyersMS enabled auto-merge (squash) April 13, 2026 22:50
@AndyAyersMS
Copy link
Copy Markdown
Member Author

/ba-g dead-letter mac catalyst

@AndyAyersMS AndyAyersMS merged commit 578644c into dotnet:main Apr 13, 2026
142 of 145 checks passed
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.

JIT: missing opportunity for RBO

3 participants