Skip to content

[NativeAot] Devirtualization opportunity around field loads #74000

@MichalStrehovsky

Description

@MichalStrehovsky

Notice the first interface call is not devirtualized, only the second, after storing to a local.

using System;
using System.Runtime.CompilerServices;

interface IFoo
{
    void Frob();
}

class Program : IFoo
{
    static IFoo theFoo = new Program();

    public void Frob() => Console.WriteLine("Hello");

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Main()
    {
        theFoo.Frob();
        IFoo i = theFoo;
        i.Frob();
    }
}
00007FF796607C10 56                   push        rsi  
00007FF796607C11 48 83 EC 20          sub         rsp,20h  
00007FF796607C15 E8 8B A8 D4 FF       call        __GetGCStaticBase_repro_Program (07FF7963524A5h)  
00007FF796607C1A 48 8B F0             mov         rsi,rax  
00007FF796607C1D 48 8B 4E 08          mov         rcx,qword ptr [rsi+8]  
00007FF796607C21 4C 8D 15 A8 EC 27 00 lea         r10,[__InterfaceDispatchCell_repro_IFoo__Frob_repro_Program__Main (07FF7968868D0h)]  
00007FF796607C28 41 FF 12             call        qword ptr [r10]  
00007FF796607C2B 48 8B 4E 08          mov         rcx,qword ptr [rsi+8]  
00007FF796607C2F 38 09                cmp         byte ptr [rcx],cl  
00007FF796607C31 48 8D 0D 30 47 26 00 lea         rcx,[__Str_Hello (07FF79686C368h)]  
00007FF796607C38 E8 13 26 00 00       call        System_Console_System_Console__WriteLine_12 (07FF79660A250h)  
00007FF796607C3D 90                   nop  
00007FF796607C3E 48 83 C4 20          add         rsp,20h  
00007FF796607C42 5E                   pop         rsi  
00007FF796607C43 C3                   ret  

Cc @EgorBo

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions