Skip to content

[experiment] check generic ctx in gtGetClassHandle#129434

Closed
EgorBo wants to merge 1 commit into
dotnet:mainfrom
EgorBo:jit-gtgetclasshandle-generic-ctx
Closed

[experiment] check generic ctx in gtGetClassHandle#129434
EgorBo wants to merge 1 commit into
dotnet:mainfrom
EgorBo:jit-gtgetclasshandle-generic-ctx

Conversation

@EgorBo

@EgorBo EgorBo commented Jun 15, 2026

Copy link
Copy Markdown
Member

Experiment: in gtGetClassHandle's CT_USER_FUNC branch, recover the exact return type of a non-inlined shared generic call from its instantiation parameter (WellKnownArg::InstParam), mirroring the sharpening already done for inline candidates. This lets a subsequent virtual call on the result devirtualize exactly (e.g. NoInline(new Foo()).ToString() folds without a GDV guard) instead of seeing System.__Canon.

Note

This PR was created with assistance from GitHub Copilot.

Recover the exact return type of a non-inlined shared generic call from
its instantiation parameter, so the result can be exactly devirtualized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 15, 2026 18:01
@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 Jun 15, 2026
@EgorBo

EgorBo commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

Just a CI test for an alternative fix #129373 tries to make.

@EgorBo

EgorBo commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

@MihuBot -nuget -jitutils-repo EgorBo/jitutils -jitutils-branch pmi-deterministic-cctors

@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

This PR adjusts CoreCLR JIT’s Compiler::gtGetClassHandle handling of GT_CALL nodes (specifically CT_USER_FUNC) to attempt to recover a more precise instantiated return type for shared generic calls by using the call’s WellKnownArg::InstParam, similar in spirit to the existing inline-candidate sharpening.

Changes:

  • Remove outdated comment implying exact generic context is always unavailable for CT_USER_FUNC calls.
  • When the return type from eeGetMethodSig is a shared instantiation (e.g., __Canon), attempt to re-query the signature in the exact context derived from WellKnownArg::InstParam and use the refined return type when it is no longer shared.

Comment on lines +20893 to +20895
// Static method on a generic type (or array method): the
// generic context is the exact owner class.
CORINFO_CLASS_HANDLE exactOwner = gtGetHelperArgClassHandle(instParam->GetNode());
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants