Repository navigation
JIT: Fix bug in GenTree::Equals - #128654
Conversation
Make sure we properly distinguish virtual stub calls to avoid incorrect head/tail merges. Fixes dotnet#128631. Co-authored-by: Copilot <[email protected]>
|
@EgorBo PTAL |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR fixes JIT call-node equality so virtual stub dispatch calls with different dispatch cells are not considered interchangeable, preventing incorrect head/tail merging for shared-generic interface dispatch.
Changes:
- Compares
gtStubCallStubAddrfor virtual stub calls inGenTreeCall::Equals. - Adds a JIT regression test for distinct shared-generic interface dispatch sites.
- Registers the new regression test in the JIT regression project.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/coreclr/jit/gentree.cpp |
Adds virtual stub address comparison to call equality. |
src/tests/JIT/Regression/JitBlue/Runtime_128631/Runtime_128631.cs |
Adds regression coverage for the dispatch-cell merge bug. |
src/tests/JIT/Regression/Regression_ro_2.csproj |
Includes the new regression test in the read-only regression set. |
Ensures the regression test reliably exercises the head/tail-merge shape even if a caller would otherwise inline `Dispatch` with constant tags. Co-authored-by: Copilot <[email protected]>
|
Looking more broadly at |
Opened #128659 for this. |
|
No diffs locally (not too surprising as this has slipped past our testing). |
|
No diffs in CI either. |
|
/backport to release/10.0 |
|
Started backporting to |
|
@AndyAyersMS backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: JIT: Compare stub addresses in GenTreeCall::Equals
Using index info to reconstruct a base tree...
M src/coreclr/jit/gentree.cpp
A src/tests/JIT/Regression/Regression_ro_2.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/jit/gentree.cpp
CONFLICT (modify/delete): src/tests/JIT/Regression/Regression_ro_2.csproj deleted in HEAD and modified in JIT: Compare stub addresses in GenTreeCall::Equals. Version JIT: Compare stub addresses in GenTreeCall::Equals of src/tests/JIT/Regression/Regression_ro_2.csproj left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 JIT: Compare stub addresses in GenTreeCall::Equals
Error: The process '/usr/bin/git' failed with exit code 128 |
Make sure to properly distinguish virtual stub calls to avoid incorrect head/tail merges. Fixes #128631. Backport of #128654 to release/10.0 ## Customer Impact - [x] Customer reported - [ ] Found internally A bug in the JIT's tail merge optimization can cause the wrong method to be invoked. The pattern required is a shared generic method invoked at two sibling tail call sites on differently typed objects with otherwise identical arguments. These calls are only distinguishable by the different virtual stub addresses, and the JIT was not considering these when checking if the calls were identical. EG in a case like ```C# if (tag == "bytes") return ((IFoo<byte[]>)this).Get(); if (tag == "string") return ((IFoo<string>)this).Get(); ``` The JIT can collapse the two calls into one and so invoke the wrong method for one of the cases. ## Regression - [x] Yes - introduced in .NET 8 by #77103. - [ ] No It is harder to reproduce in .NET 8 as the optimization was less general back then. ## Testing Verified fix with customer repro and locally crafted repro case. ## Risk Low. Adds some extra checking to the method that tail merging uses to determine if two calls are identical. Overall the JIT becomes (properly) more cautions about this optimization. No diffs in SPMI. Co-authored-by: Copilot <[email protected]>
Make sure we properly distinguish virtual stub calls to avoid incorrect head/tail merges. Fixes #128631. --------- Co-authored-by: Copilot <[email protected]>
Make sure we properly distinguish virtual stub calls to avoid incorrect head/tail merges.
Fixes #128631.