Skip to content

JIT: Validate jump threading phi inputs - #134205

Open
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:fix-133981-jump-thread-phi
Open

AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:fix-133981-jump-thread-phi

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Jump threading can see an incomplete phi after an earlier flow edit. The SSA
replacement logic only checked the phi arguments that remained, so it could
remove the phi and rewrite uses without accounting for every predecessor.

Require the block and successor replacement paths to cover every expected
predecessor before accepting a common SSA definition. Otherwise, conservatively
skip the rewrite.

Add a regression case to JumpThreadPhi that returned 101 instead of 200 before
the fix.

Validation:

  • Windows x64 Checked JIT build and matching Core_Root
  • JumpThreadPhi: 2 passed; new test fails before the fix and passes after it
  • Standalone repro: 101 before, 200 after
  • JIT formatting
  • Windows x64 Release SuperPMI: 0 failures; 11 stable textual diffs across the
    four affected collections, +82 bytes over about 1.86 million sequentially
    replayed contexts

Resolves #133981

Note

This pull request description was generated with GitHub Copilot.

Jump threading could remove a phi without accounting for all remaining
predecessors, producing an invalid SSA rewrite. Require complete predecessor
coverage before replacing phi uses.

Fixes dotnet#133981

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19e3976f-8f3e-4ab8-973d-d568620770c1
Copilot AI lite review requested due to automatic review settings September 18, 2026 16:21
@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 Sep 18, 2026
@AndyAyersMS
AndyAyersMS requested a review from EgorBo September 18, 2026 16:22
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@EgorBo PTAL
fyi @dotnet/jit-contrib

A couple of SPMI diffs.

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.

🟡 Changes recommended

A critical finding remains: count-only phi coverage can accept a missing current predecessor when stale phi arguments remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR hardens JIT jump-threading SSA replacement against incomplete phi inputs and adds regression coverage.

Changes:

  • Adds predecessor-coverage checks for block and successor rewrites.
  • Adds the Phi_01 regression test.
File summaries
File Summary
src/tests/JIT/opt/RedundantBranch/JumpThreadPhi.cs Adds regression coverage for incorrect output.
src/coreclr/jit/redundantbranchopts.cpp Adds phi predecessor coverage checks.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/coreclr/jit/redundantbranchopts.cpp Outdated
Compare predecessor identities when validating threaded PHI replacements. This
prevents stale PHI arguments from masking missing current predecessors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19e3976f-8f3e-4ab8-973d-d568620770c1
Copilot AI review requested due to automatic review settings September 18, 2026 23:53

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.

Copilot review overview

🟢 Approval recommended

The reviewed changes address the miscompilation and include regression coverage with no unresolved blocking issues.

Review effort: Lite
Findings: None

Resolved since last review (1)

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@EgorBo revised to a more exact check, ptal

@AndyAyersMS
AndyAyersMS requested a review from EgorBo September 19, 2026 01:17
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: (bug) jump threading deletes a PHI and rewrites its uses with an SSA def that does not reach all remaining predecessors

3 participants