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
Since
IMyInterfacehas only one implementation (monomorphic cases aren't rare) we can optimizeisinstto basicallyo is MyProgramand inline it.Current NativeAOT codegen:
Expected NativeAOT codegen:
cc @MichalStrehovsky