Skip to content

JIT: refine SSA info in ambiguously threaded blocks#126907

Merged
AndyAyersMS merged 6 commits intodotnet:mainfrom
AndyAyersMS:AssertionPropNonNegative
Apr 21, 2026
Merged

JIT: refine SSA info in ambiguously threaded blocks#126907
AndyAyersMS merged 6 commits intodotnet:mainfrom
AndyAyersMS:AssertionPropNonNegative

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS commented Apr 14, 2026

If we partially jump-thread a block with PHIs, the remaining preds that target block may all bring in the same SSA def for some of the PHIs. If so, remove the PHIs and update the SSA/VN for the PHI uses in the block.

In particular there may just be one ambiguous pred.

Fixes #126703.

If we partially jump-thread a block with PHIs, the remaining preds that target
block may all bring in the same SSA def for some of the PHIs. If so, remove the
PHIs and update the SSA/VN for the PHI uses in the block.

In particular there may just be one ambiguous pred.

Also: enhance AP slightly to handle non-negative cases.

Fixes dotnet#126703.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 21:03
@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 14, 2026
@AndyAyersMS
Copy link
Copy Markdown
Member Author

AndyAyersMS commented Apr 14, 2026

@EgorBo PTAL
fyi @dotnet/jit-contrib

diffs [updated]

@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

Refines CoreCLR JIT optimizations around jump-threading through PHI-containing blocks by improving SSA/VN rewriting when only ambiguously-threaded predecessors remain, and adds a small assertion propagation enhancement to fold comparisons against negative constants when the compared value is proven non-negative.

Changes:

  • Track and remove redundant PHI-def statements in partially jump-threaded blocks when remaining incoming paths agree on the same SSA def, and rewrite SSA/VN for affected uses.
  • Adjust successor SSA replacement computation to reflect post-threading reaching paths.
  • Enhance assertion propagation to fold ==/!= against negative constants when the value is known non-negative; add a regression test with disasm CHECKs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/tests/JIT/opt/RedundantBranch/JumpThreadPhi.cs Adds disasm CHECK expectations to validate improved codegen for the repro pattern.
src/coreclr/jit/redundantbranchopts.cpp Implements PHI-use rewriting + optional PHI removal when ambiguous preds converge on a single SSA def after partial threading.
src/coreclr/jit/assertionprop.cpp Adds folding for X ==/!= (negative const) when X is proven never-negative.

Comment thread src/tests/JIT/opt/RedundantBranch/JumpThreadPhi.cs Outdated
@AndyAyersMS
Copy link
Copy Markdown
Member Author

From the inspiring example

image (25) Control flow and IR before RBO. We are going to jump thread through BB4, but it's only partial threading since we don't know how BB4's predicate evaluates when control comes from BB3.
image (24) Partial jump threading is done.

This is how things are left in main. But with this PR we now realize that there is just one reaching def for V3 in BB4, and so we rewrite the use and remove the PHI

image (26) Assertion prop is then able to propagate the "never negative" range and eliminate the compare in BB4.
image (28) Post-AP there is just one compare left...

Comment thread src/coreclr/jit/assertionprop.cpp Outdated
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