Skip to content

JIT: Unify to instParamLookup and improve GVM test coverage#126947

Open
hez2010 wants to merge 41 commits into
dotnet:mainfrom
hez2010:shared-gvm-devirt/1-tests-instparamlookup
Open

JIT: Unify to instParamLookup and improve GVM test coverage#126947
hez2010 wants to merge 41 commits into
dotnet:mainfrom
hez2010:shared-gvm-devirt/1-tests-instparamlookup

Conversation

@hez2010
Copy link
Copy Markdown
Contributor

@hez2010 hez2010 commented Apr 15, 2026

Extracted from #123323. This PR is the first step in splitting the shared GVM devirtualization work.

It does two things:

  • expands the generic virtual method test coverage so the later enablement PRs have good coverage
  • refactors devirtualization a bit to replace multiple ad-hoc flags in CORINFO_DEVIRTUALIZATION_INFO with a single instParamLookup

Contributes to #112596

/cc: @jakobbotsch

Copilot AI review requested due to automatic review settings April 15, 2026 12:57
@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 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Apr 15, 2026
@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.

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

Refactors CoreCLR devirtualization metadata to use a unified instParamLookup and expands JIT test coverage for generic virtual method (GVM) scenarios to support follow-on GVM devirtualization work.

Changes:

  • Add a new GVM-focused runtime lookup/delegate test to broaden devirtualization coverage.
  • Replace CORINFO_DEVIRTUALIZATION_INFO ad-hoc flags with instParamLookup, and update JIT devirtualization logic to consume it.
  • Update SuperPMI and the managed JitInterface type definitions/serialization to match the new CORINFO_DEVIRTUALIZATION_INFO shape (plus bump the JIT/EE versioning GUID).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tests/JIT/Generics/VirtualMethods/generic_virtual_methods.cs Adds additional GVM/runtime-lookup-related test coverage.
src/coreclr/vm/jitinterface.cpp Initializes/produces instParamLookup for devirtualization results (replacing older flags).
src/coreclr/jit/importercalls.cpp Plumbs instParamLookup through devirtualization + guarded devirtualization candidate tracking and inserts instantiation args when required.
src/coreclr/jit/morph.cpp Simplifies lookup-tree helpers to take CORINFO_LOOKUP directly.
src/coreclr/jit/compiler.h Updates declarations for the new lookup-tree helper signatures and GDV candidate plumbing.
src/coreclr/inc/corinfo.h Updates CORINFO_DEVIRTUALIZATION_INFO to carry instParamLookup instead of legacy flags; documents “no lookup needed” sentinel.
src/coreclr/inc/jiteeversionguid.h Bumps the JIT/EE version GUID for the interface change.
src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs Mirrors the CORINFO_DEVIRTUALIZATION_INFO layout change in managed definitions.
src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs Updates managed resolveVirtualMethod implementation to populate instParamLookup and method-context behavior.
src/coreclr/tools/superpmi/superpmi-shared/agnostic.h Updates SuperPMI record structs to include instParamLookup.
src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp Records/restores/dumps instParamLookup in SuperPMI method contexts.

Comment thread src/coreclr/vm/jitinterface.cpp
Comment thread src/coreclr/jit/importercalls.cpp Outdated
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented Apr 16, 2026

Test failure seems unrelated.

@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented Apr 24, 2026

Ping @jakobbotsch

This is a refactor only change which is the prerequisites of the upcoming GVM devirt work, please take a look when you get some time.

@MichalPetryka
Copy link
Copy Markdown
Contributor

@MihuBot

Comment thread src/coreclr/inc/corinfo.h Outdated
Copilot AI review requested due to automatic review settings April 25, 2026 11:55
@hez2010 hez2010 force-pushed the shared-gvm-devirt/1-tests-instparamlookup branch from 75dec5b to 4da609f Compare April 25, 2026 11:55
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

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

Comment thread src/tests/JIT/Generics/VirtualMethods/generic_virtual_methods.cs
Comment thread src/coreclr/vm/jitinterface.cpp
Comment thread src/coreclr/jit/importercalls.cpp Outdated
@hez2010 hez2010 force-pushed the shared-gvm-devirt/1-tests-instparamlookup branch from 4da609f to 42d5011 Compare April 25, 2026 12:19
Copilot AI review requested due to automatic review settings April 25, 2026 12:35
Comment thread src/coreclr/jit/importercalls.cpp Outdated
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

Test failures seem unrelated?

@jakobbotsch
Copy link
Copy Markdown
Member

@MihuBot

@jakobbotsch
Copy link
Copy Markdown
Member

It seems there are diffs. Can you take a look at why? I was hoping this could be a zero diff change with all diffs coming as follow-ups.

@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

It seems there are diffs. Can you take a look at why? I was hoping this could be a zero diff change with all diffs coming as follow-ups.

I think it's because this branch is a bit stale? We merged a devirtualization improvement several hours ago but didn't sync that to this branch yet.

Copilot AI review requested due to automatic review settings May 23, 2026 11:53
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

@MihuBot

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

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

Comment thread src/coreclr/jit/morph.cpp
Comment thread src/coreclr/jit/importercalls.cpp Outdated
Comment thread src/tests/JIT/Generics/VirtualMethods/generic_virtual_methods.cs
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

@MihuBot

@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

Previously we only check isExact when the EE sets isInstantiatingStub to true, but now we are checking it unconditionally as long as it's array interface devirt, and the EE no longer returns such a flag. So it rejects more array interface devirt than before.

However, the original "array is inexact" guard was added to workaround a bug in #116771 (comment). But with this PR, we now have the correct instantiating stub in tokenForLookup and we no longer need to do a getInstantiatedEntry round-trip, so the original bug doesn't exist anymore: we now always have the right instantiation here.

For comparison, for this tree

**** Late devirt opportunity
               [000157] --C-G------                         *  CALLV stub ref    System.Collections.Generic.IEnumerable`1[System.__Canon]:GetEnumerator():System.Collections.Generic.IEnumerator`1[System.__Canon]:this
               [000820] --CXG------ this                    \--*  CALL help ref    CORINFO_HELP_CHKCASTANY
               [000819] H------N--- arg0                       +--*  CNS_INT(h) long   0x7ffe0b544f48 class System.Collections.Generic.IEnumerable`1[Span.InlineDataAttribute]
               [000830] --C-G------ arg1                       \--*  CALL      ref    System.Attribute:GetCustomAttributes(System.Reflection.MemberInfo,System.Type,bool):System.Attribute[]
               [000145] ----------- arg0                          +--*  LCL_VAR   ref    V18 tmp5         
               [000827] --C-G------ arg1                          +--*  CALL help ref    CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
               [000828] H---------- arg0                          |  \--*  CNS_INT(h) long   0x7ffe0b5441d0 class Span.InlineDataAttribute
               [000829] ----------- arg2                          \--*  CNS_INT   int    1

previously we end up with

               [000157] --C-G------                         *  CALL nullcheck ref    System.SZArrayHelper:GetEnumerator[System.__Canon]():System.Collections.Generic.IEnumerator`1[System.__Canon]:this
               [000820] --CXG------ this                    +--*  CALL help ref    CORINFO_HELP_CHKCASTANY
               [000819] H------N--- arg0                    |  +--*  CNS_INT(h) long   0x7ffe0b544f48 class System.Collections.Generic.IEnumerable`1[Span.InlineDataAttribute]
               [000830] --C-G------ arg1                    |  \--*  CALL      ref    System.Attribute:GetCustomAttributes(System.Reflection.MemberInfo,System.Type,bool):System.Attribute[]
               [000145] ----------- arg0                    |     +--*  LCL_VAR   ref    V18 tmp5         
               [000827] --C-G------ arg1                    |     +--*  CALL help ref    CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
               [000828] H---------- arg0                    |     |  \--*  CNS_INT(h) long   0x7ffe0b5441d0 class Span.InlineDataAttribute
               [000829] ----------- arg2                    |     \--*  CNS_INT   int    1
               [000832] H---------- gctx                    \--*  CNS_INT(h) long   0x7ffe0b5caa68 method System.SZArrayHelper:GetEnumerator[System.Attribute]():System.Collections.Generic.IEnumerator`1[System.Attribute]:this

and now we have

               [000157] --C-G------                         *  CALL nullcheck ref    System.SZArrayHelper:GetEnumerator[System.__Canon]():System.Collections.Generic.IEnumerator`1[System.__Canon]:this
               [000850] --CXG------ this                    +--*  CALL help ref    CORINFO_HELP_CHKCASTANY
               [000849] H------N--- arg0                    |  +--*  CNS_INT(h) long   0x7ffab5805780 class System.Collections.Generic.IEnumerable`1[Span.InlineDataAttribute]
               [000860] --C-G------ arg1                    |  \--*  CALL      ref    System.Attribute:GetCustomAttributes(System.Reflection.MemberInfo,System.Type,bool):System.Attribute[]
               [000145] ----------- arg0                    |     +--*  LCL_VAR   ref    V18 tmp5
               [000857] --C-G------ arg1                    |     +--*  CALL help ref    CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
               [000858] H---------- arg0                    |     |  \--*  CNS_INT(h) long   0x7ffab5804a18 class Span.InlineDataAttribute
               [000859] ----------- arg2                    |     \--*  CNS_INT   int    1
               [000862] H---------- gctx                    \--*  CNS_INT(h) long   0x7ffab5808a40 method System.SZArrayHelper:GetEnumerator[Span.InlineDataAttribute]():System.Collections.Generic.IEnumerator`1[Span.InlineDataAttribute]:this

We no longer have the issue on incorrect inst param now. So I would recommend removing this invalid guard. (already done in eaca574).

But that's say, to keep this PR zero diff, we will need to introduce the isInstantiatingStub flag back, or checking instParamLookup.constLookup.handle or the signature manually in the JIT. What do you think? @jakobbotsch

Comment thread src/coreclr/inc/corinfo.h Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 16:20
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

@MihuBot

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread src/coreclr/jit/importercalls.cpp
Comment thread src/coreclr/jit/indirectcalltransformer.cpp
Comment thread src/coreclr/jit/compiler.h
Comment thread src/tests/JIT/Generics/VirtualMethods/generic_virtual_methods.cs
Copilot AI review requested due to automatic review settings May 23, 2026 16:49
@hez2010 hez2010 force-pushed the shared-gvm-devirt/1-tests-instparamlookup branch from aba164b to d02eec1 Compare May 23, 2026 16:49
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

@MihuBot

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Comment thread src/tests/JIT/Generics/VirtualMethods/generic_virtual_methods.cs
Comment thread src/coreclr/jit/compiler.h
@hez2010
Copy link
Copy Markdown
Contributor Author

hez2010 commented May 23, 2026

Now it's zero diff as expected.

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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants