-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
Milestone
Description
Currently, getExactClasses gives up if the base type is not an interface so if we have something like this it won't be optimized:
using System.Runtime.CompilerServices;
public class ClassA
{
public virtual int GetValue() => 42;
}
public class ClassB : ClassA
{
// we don't even need to override GetValue here
}
class MyClass
{
static void Main()
{
Test(new ClassB());
}
[MethodImpl(MethodImplOptions.NoInlining)]
static int Test(ClassA c) => c.GetValue();
}Current codegen of Test on NativeAOT:
; Method MyClass:Test(ClassA):int (FullOpts)
sub rsp, 40
mov rax, qword ptr [rcx]
call [rax+30H]ClassA:GetValue():int:this
nop
add rsp, 40
ret
; Total bytes of code: 16Expected codegen:
; Method MyClass:Test(ClassA):int (FullOpts)
cmp byte ptr [rcx], cl ; nullcheck
mov eax, 42
ret
; Total bytes of code: 8Presumably, this needs no changes on the jit side, only that getExactClasses should be improved on the NAOT side.
cc @dotnet/ilc-contrib
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status