Skip to content

[Release/10.0] JIT: Fix bug in GenTree::Equals (#128654)#128724

Merged
JulieLeeMSFT merged 1 commit into
dotnet:release/10.0from
AndyAyersMS:Port128654toRelease10.0
May 29, 2026
Merged

[Release/10.0] JIT: Fix bug in GenTree::Equals (#128654)#128724
JulieLeeMSFT merged 1 commit into
dotnet:release/10.0from
AndyAyersMS:Port128654toRelease10.0

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

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

  • 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

        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

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.

Make sure we properly distinguish virtual stub calls to avoid incorrect
head/tail merges.

Fixes dotnet#128631.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit dfd91b8)
Copilot AI review requested due to automatic review settings May 28, 2026 20:11
@AndyAyersMS AndyAyersMS requested a review from jakobbotsch May 28, 2026 20: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 May 28, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@jakobbotsch @JulieLeeMSFT PTAL
fyi @dotnet/jit-contrib

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

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.

Pull request overview

Backport of #128654 to release/10.0. Fixes a JIT tail-merge bug where two shared-generic virtual stub calls with distinct stub dispatch cells were considered equal by GenTree::Equals, causing the JIT to merge them and dispatch to the wrong method.

Changes:

  • Add a stub-address check in GenTreeCall::Equals so virtual stub calls are only considered equal when their dispatch cells match.
  • Add a JitBlue regression test (Runtime_128631) covering two sibling shared-generic interface calls.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/gentree.cpp Adds virtual stub address comparison in GenTreeCall::Equals to prevent incorrect head/tail merges.
src/tests/JIT/Regression/JitBlue/Runtime_128631/Runtime_128631.cs New regression test exercising two shared-generic interface dispatches that must not be merged.
src/tests/JIT/Regression/JitBlue/Runtime_128631/Runtime_128631.csproj Test project file for the new regression test.

@AndyAyersMS AndyAyersMS changed the title JIT: Fix bug in GenTree::Equals (#128654) [Release/10.0] JIT: Fix bug in GenTree::Equals (#128654) May 28, 2026

@JulieLeeMSFT JulieLeeMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@JulieLeeMSFT JulieLeeMSFT added the Servicing-consider Issue for next servicing release review label May 28, 2026
@JulieLeeMSFT JulieLeeMSFT added this to the 10.0.x milestone May 28, 2026
@JulieLeeMSFT

Copy link
Copy Markdown
Member

@AndyAyersMS, please check test failrues.

@AndyAyersMS

Copy link
Copy Markdown
Member Author

Failures are mono / timeouts. Unrelated.

@JulieLeeMSFT

Copy link
Copy Markdown
Member

/ba-g all known issues, and mono failures are unrelated

@JulieLeeMSFT JulieLeeMSFT merged commit aa57b51 into dotnet:release/10.0 May 29, 2026
119 of 128 checks passed
@snakefoot

snakefoot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Guess it will be part of the next milestone 10.0.10 ?

@github-actions github-actions Bot locked and limited conversation to collaborators Jul 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants