Skip to content

NativeAOT: devirtualize isinst for monomorphic cases #80828

Description

@EgorBo
publicinterfaceIMyInterface{}publicclassMyProgram:IMyInterface{staticvoidMain()=>IsMyInterface(newMyProgram());[MethodImpl(MethodImplOptions.NoInlining)]staticboolIsMyInterface(objecto)=>oisIMyInterface;}

Since IMyInterface has only one implementation (monomorphic cases aren't rare) we can optimize isinst to basically o is MyProgram and inline it.

Current NativeAOT codegen:

; Method Program:IsMyInterface(System.Object):bool 4883EC28 subrsp,40 488BD1 movrdx,rcx 488D0D00000000 learcx,[(reloc 0x40000000004234f8)] E800000000 call CORINFO_HELP_ISINSTANCEOFINTERFACE 4885C0 testrax,rax 0F95C0 setne al 0FB6C0 movzxrax,al 4883C428 addrsp,40 C3 ret; Total bytes of code: 33

Expected NativeAOT codegen:

; Method Program:IsMyInterface(System.Object):bool 4885C9 testrcx,rcx 740E je SHORT G_M18292_IG05 488D0500000000 learax,[(reloc 0x40000000004221d8)]483901cmp qword ptr [rcx],rax7402je SHORT G_M18292_IG05 33C9 xorrcx,rcxG_M18292_IG05: 33C0 xoreax,eax 4885C9 testrcx,rcx 0F95C0 setne al C3 ret; Total bytes of code: 28

cc @MichalStrehovsky

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions