Repository navigation
JIT: fix profile weights when folding switches with self-edges - #137702
Conversation
Use the original block weight for each removed edge. Add a regression test. Co-authored-by: Copilot <[email protected]> Copilot-Session: c2f2ea71-2c5f-41c9-b7ed-b1d9af3d1ba7
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
@EgorBo ptal |
|
@AndyAyersMS it seems there are similar places in JIT like this, my local AI run found these: 643cff9 |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change addressing traversal-order-dependent profile weights in constant switches with self-edges.
No open issues 🎉
What changed in this PR
This PR corrects JIT profile-weight adjustments when folding a constant switch with a self-edge, preventing successor weights from depending on traversal order.
Changes:
- Snapshot the switch block’s weight before subtracting outgoing edge contributions.
- Add a correctness regression test covering a constant switch with a self-edge; it does not directly assert profile weights.
| File | Description |
|---|---|
src/tests/JIT/Regression_ro_2/Runtime_137642.cs |
Adds a self-edge switch test that checks the selected branch’s result. |
src/coreclr/jit/morph.cpp |
Uses the original block weight for all successor-weight deductions. |
Review effort: Balanced
Apply the same self-edge fix to fgConvertBBToThrowBB, fgUnreachableBlock, and LowerReturnSuspend. Co-authored-by: Copilot <[email protected]> Copilot-Session: c2f2ea71-2c5f-41c9-b7ed-b1d9af3d1ba7
|
Thanks, I applied the same snapshot fix to Note This comment was generated with GitHub Copilot. |
When folding a constant switch whose block is also one of its own successors, the self-edge is visited while subtracting edge weights, which lowers the block's weight before the remaining edges are processed. Later successors then use the reduced weight, so removed blocks keep stale weight and the retained target ends up too heavy (e.g.
0.05/1.05instead of0/1).Snapshot the block weight once before adjusting successors.
The regression test is a plain correctness test; the bad weights are transient (the fold marks the profile inconsistent and post-morph repair resynthesizes), so the test doesn't check them directly. Verified the fix via JIT dump with
DOTNET_JitSynthesizeCounts=1.Resolves #137642
Note
This PR description was generated with GitHub Copilot.