Skip to content

JIT: Renable SSA-aware PHI jump threading#127103

Open
AndyAyersMS wants to merge 1 commit intodotnet:mainfrom
AndyAyersMS:Fix126976
Open

JIT: Renable SSA-aware PHI jump threading#127103
AndyAyersMS wants to merge 1 commit intodotnet:mainfrom
AndyAyersMS:Fix126976

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

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.

Fix included here that was not in #126812: ensure that field uses of locals get the proper VN updates.

Fixes #126976.

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.

Fix included here that was not in dotnet#126812: ensure that field uses of locals get
the proper VN updates.

Fixes dotnet#126976.
@AndyAyersMS AndyAyersMS requested review from EgorBo and Copilot April 18, 2026 02:11
@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 18, 2026
@AndyAyersMS
Copy link
Copy Markdown
Member Author

AndyAyersMS commented Apr 18, 2026

@EgorBo PTAL
fyi @dotnet/jit-contrib

diffs

More or less the same as the initial PR.

@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

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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 updates CoreCLR JIT redundant branch elimination (jump threading) to better handle SSA-aware PHI cases by allowing threading when PHI uses can be safely resolved and by keeping SSA/VN state consistent when rewriting those uses.

Changes:

  • Adjust jump-thread viability checks to treat “global PHI uses” as potentially resolvable (rather than an immediate bail-out), enabling PHI-based threading in more cases.
  • Update successor SSA uses during threading and fix VN rewriting for GT_LCL_FLD so field loads get the correct derived field VN from the replacement SSA def.

{
continue;
}
assert(oldSsaNum != phiUse.m_replacementSsaNum);
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

The new assert assumes the replacement SSA is always different from the current SSA. In some control-flow shapes (e.g., backedge PHI args that reuse the PHI SSA when the variable is not redefined on that edge), replacement can legitimately equal oldSsaNum. In that case we should treat this as a no-op and avoid calling AddUse again (which can double-count uses). Please restore the previous early-continue (or otherwise handle the equal case) instead of asserting.

Suggested change
assert(oldSsaNum != phiUse.m_replacementSsaNum);
if (oldSsaNum == phiUse.m_replacementSsaNum)
{
continue;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't jump thread blocks with self-loops, so seeing the same SSA def here is unexpected.

Comment on lines 1765 to 1766
JITDUMP(FMT_BB " has global phi for V%02u.%u; no phi-based threading\n", block->bbNum, lclNum,
ssaNum);
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

This JITDUMP message says "no phi-based threading" but the code no longer returns here (it just sets hasGlobalPhiUses and later may still allow threading after optCanRewritePhiUses). Please update the message to reflect the new behavior (e.g., that global PHI uses require additional resolution) to avoid misleading diagnostics when debugging jump threading decisions.

Suggested change
JITDUMP(FMT_BB " has global phi for V%02u.%u; no phi-based threading\n", block->bbNum, lclNum,
ssaNum);
JITDUMP(FMT_BB " has global phi for V%02u.%u; additional phi-use resolution may be required\n",
block->bbNum, lclNum, ssaNum);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will fix this later, if there's no other feedback.

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: fix issue in ssa-aware jump threading

2 participants