JIT: support SSA-aware PHI jump threading#126812
Conversation
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>
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
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. |
|
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 |
EgorBo
left a comment
There was a problem hiding this comment.
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. |
|
Linux x64 is probably most representative, other os/arch seem to be missing some collections. |
|
/ba-g dead-letter mac catalyst |
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)