Inliner: don't give up on virtual calls if we can clarify their exact targets after inlining #85209
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Current codegen for
Test()
:SayHello
is not inlined despite being devirtualized and marked asAggressiveInlining
. This demonstrates a fundamental problem in the JIT's inliner - it does inlining in, roughly, two stages: 1) Traverse all calls and set inline candidates + spill candidates to be top-level statements. 2) Inline all candidates we previosly found. During the first stage we give up onSayHello
because the target is abstract (ClassA
) - we don't know yet that if we inlineGetClassA
we'll get the exact target (ClassB
). What is funny that Dynamic PGO can help us here - it will try to inline it asClassB
under a guard (GDV) and then we'll fold the guard once we clarify the target (#84661), so the same codegen when PGO is enabled looks like this:No guards, call is inlined!
We should be able to do the same without PGO too (e.g. for NativeAOT). This limitation is the exact reason why APIs like
Encoding.UTF8.X
,Encoding.ASCII.X
,ArrayPool.Shared.X
etc are never inlined without PGO.cc @AndyAyersMS (we discussed this case today in Discord)
The text was updated successfully, but these errors were encountered: