Skip to content

NativeAOT: missed devirtualization for isinst #136302

Closed

Description

@EgorBo
using System;
using System.Runtime.CompilerServices;

class Program
{
    static void Main()
    {
        Test(new A());
        Test(new B());
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Test(object o)
    {
        if (o is A)
            Console.WriteLine("A!");
    }
}

class A {}
class B : A { }

Codegen for Test:

Program:Test(System.Object) (FullOpts):
       push     rax
       mov      rsi, rdi
       lea      rdi, [(reloc 0x43d5a8)]      ; A
       call     CORINFO_HELP_ISINSTANCEOFCLASS
       test     rax, rax
       je       SHORT G_M3485_IG04
       lea      rdi, gword ptr [(reloc 0x43d620)]      ; '"A!"'
       call     System.Console:WriteLine(System.String)
G_M3485_IG04:  ;; offset=0x0021
       nop      
       add      rsp, 8
       ret      

Expected: No CORINFO_HELP_ISINSTANCEOFCLASS call

Activity

  1. added
    untriaged
    on Oct 22, 2026
  2. added
    area-CodeGen-coreclr
    on Oct 22, 2026
  3. removed
    untriaged
    on Oct 22, 2026
  4. added this to the Future milestone on Oct 22, 2026
  5. dotnet-policy-service commented on Oct 22, 2026

    @dotnet-policy-service
    Contributor

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

  6. EgorBo commented on Oct 22, 2026

    @EgorBo
    MemberAuthor

    Hm.. looks like NAOT correctly returns A, B for get-exact-classes, but jit bails out here:

    // TODO-InlineCast: we shouldn't need isExactType check, otherwise we skip cases like this:
    //
    // if (obj is IMyInterface) { ... }
    //
    // class MyClass : IMyInterface
    // class MySubClass : MyClass
    //
    // (and both classes are the only ones implementing the interface)
    //
    if (!comp->info.compCompHnd->isExactType(exactClasses[i]))

    not sure if it can be lifted tbh.

  7. added a commit that references this issue on Oct 23, 2026
    27123d2
  8. locked and limited conversation to collaborators on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclr

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions