Skip to content

JIT: remove unnecessary inlining restriction #116773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025

Conversation

AndyAyersMS
Copy link
Member

We can still inline methods even if they make generic virtual calls.

Fixes #116740.

We can still inline methods even if they make generic virtual calls.

Fixes dotnet#116740.
@Copilot Copilot AI review requested due to automatic review settings June 18, 2025 01:19
@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 18, 2025
Copy link
Contributor

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

This PR removes the special-case restriction that prevented methods making generic virtual calls from being inlined, allowing the JIT to inline those methods.

  • Dropped the IS_GENERIC_VIRTUAL inline observation so it’s no longer treated as a fatal inlining barrier.
  • Removed the importer logic that explicitly rejected generic virtual calls during inlining.

Reviewed Changes

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

File Description
src/coreclr/jit/inline.def Removed the IS_GENERIC_VIRTUAL observation entry.
src/coreclr/jit/importercalls.cpp Deleted the conditional that forbade inlining generic virtual calls.
Comments suppressed due to low confidence (1)

src/coreclr/jit/importercalls.cpp:182

  • Add unit tests that exercise inlining of methods containing generic virtual calls to verify the new behavior and prevent regressions.
            }

Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@AndyAyersMS
Copy link
Member Author

On the example from #116740, the inner loop is now

G_M20355_IG03:        ; offs=0x000002, size=0x000A, bbWeight=101.11, PerfScore 454.98, gcrefRegs=0002 {rcx}, byrefRegs=0000 {}, loop=IG03, BB02 [0001], byref, isz

IN0003: 000002 add      dword ptr [rcx+0x08], eax
IN0004: 000005 inc      eax
IN0005: 000007 cmp      eax, 100
IN0006: 00000A jl       SHORT G_M20355_IG03

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL

CI SPMI likely won't see anything but missing contexts. Will try and look at a bespoke SPMI diff tomorrow.

@jakobbotsch
Copy link
Member

There is another check here that will be hit when the actual GVM is not statically resolvable:

case CORINFO_VIRTUALCALL_LDVIRTFTN:
{
if (compIsForInlining())
{
compInlineResult->NoteFatal(InlineObservation::CALLSITE_HAS_CALL_VIA_LDVIRTFTN);
return TYP_UNDEF;
}

Can it be removed too?

@hez2010
Copy link
Contributor

hez2010 commented Jun 18, 2025

Related: #112353

@AndyAyersMS
Copy link
Member Author

Can it be removed too?

Seems like it can.

@AndyAyersMS
Copy link
Member Author

Results from a local bespoke asp.net SPMI (on this PR). Modest number of base context misses, so not as clean as I'd like, but the trend is clear.

Diffs are based on 198,971 contexts (108,879 MinOpts, 90,092 FullOpts).

MISSED contexts: base: 219 (0.11%), diff: 0 (0.00%)

Overall (+300,358 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
aspnet.run.windows.x64.checked.mch 74,094,557 +300,358 +21.72%
FullOpts (+300,358 bytes)
Collection Base size (bytes) Diff size (bytes) PerfScore in Diffs
aspnet.run.windows.x64.checked.mch 41,509,153 +300,358 +21.72%

and for TP (likely overstated a bit due to base misses...)

[10:30:10] Warning: Different compilers used for base and diff JITs. Results may be misleading.
[10:30:10]   Base JIT's compiler: MSVC 194334810
[10:30:10]   Diff JIT's compiler: MSVC 194435207
[10:30:10] Running throughput diff of c:\bugs\r116740\aspnet.run.windows.x64.checked.mch
[10:31:44] Asm diffs found
[10:31:44] Total instructions executed by base: 256288855154
[10:31:44] Total instructions executed by diff: 257932230848
[10:31:44] Total instructions executed delta: 1643375694 (0.64% of base)

More details: diff_summary.86.md

@MichalPetryka
Copy link
Contributor

@MihuBot

Copy link
Member

@amanasifkhalid amanasifkhalid left a comment

Choose a reason for hiding this comment

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

LGTM

@AndyAyersMS
Copy link
Member Author

/ba-g failure with no log

@AndyAyersMS AndyAyersMS merged commit 96e283d into dotnet:main Jun 19, 2025
106 of 109 checks passed
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.

JIT does not inline function with generic struct argument
5 participants