Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAOT: fold "always false" typechecks #97601

Closed
EgorBo opened this issue Jan 27, 2024 · 1 comment · Fixed by #99761
Closed

NAOT: fold "always false" typechecks #97601

EgorBo opened this issue Jan 27, 2024 · 1 comment · Fixed by #99761
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Jan 27, 2024

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 27, 2024
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 27, 2024
@ghost
Copy link

ghost commented Jan 27, 2024

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

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:

; 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.

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@EgorBo EgorBo added this to the 9.0.0 milestone Jan 27, 2024
@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label Jan 27, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Mar 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant