KEMBAR78
NAOT: fold "always false" typechecks · Issue #97601 · dotnet/runtime · GitHub
Skip to content

NAOT: fold "always false" typechecks #97601

@EgorBo

Description

@EgorBo

If an interface/abstract class has no subclasses or they were trimmed out - all typechecks against that subclass should be folded, e.g.:

interface IMyInterface { }

class Program
{
    static void Main()
    {
        Test(null);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Test(object o)
    {
        if (o is IMyInterface) // there are no types implementing this interface
            Console.WriteLine("MyInterface!");
    }
}

Current codegen with NativeAOT for Test:

; Assembly listing for method Program:Test(System.Object) (FullOpts)
       sub      rsp, 40
       mov      rdx, rcx
       lea      rcx, [(reloc 0x4000000000422e10)] ; IMyInterface
       call     CORINFO_HELP_ISINSTANCEOFINTERFACE
       test     rax, rax
       je       SHORT G_M3485_IG04
       lea      rcx, gword ptr [(reloc 0x4000000000422e28)] ; '"MyInterface!"'
       call     System.Console:WriteLine(System.String)
G_M3485_IG04:
       nop      
       add      rsp, 40
       ret      
; Total bytes of code 42

Expected codegen:

; Assembly listing for method Program:Test(System.Object) (FullOpts)
       ret      
; Total bytes of code 1,

cc @MichalStrehovsky. I presume for that we need to make 0 a meaningful result for getExactClasses API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions