Skip to content

JIT does not recognize typeof(X) == o.GetType() checks as intrinsics with R2R #97134

@jkotas

Description

@jkotas

Repro:

using System;
using System.Runtime.CompilerServices;

public sealed class Test96876
{
    public static void Main()
    {
        foo<Test96876>(new DateTime[1]);
    }

    // Validate that the type equality involving shared array types is handled correctly
    // in shared generic code.
    [MethodImpl(MethodImplOptions.NoInlining)]
    static bool foo<T>(DateTime[] list) => typeof(T[]) == list.GetType();
}

Actual result:

foo<__Canon> is optimized to return constant for JIT, but does full type check for R2R.

Expected result

foo<__Canon> is optimized to return constant for both JIT and R2R.

Optimized JIT code:

G_M10478_IG02:  ;; offset=0x0000
       cmp      byte  ptr [rdx], dl
       xor      eax, eax
                                                ;; size=4 bbWeight=1 PerfScore 3.25
G_M10478_IG03:  ;; offset=0x0004
       ret

Optimized R2R code:

G_M000_IG01:                ;; offset=0x0000
       push     rbx
       sub      rsp, 48
       mov      qword ptr [rsp+0x28], rcx
       mov      rbx, rdx

G_M000_IG02:                ;; offset=0x000D
       call     [CORINFO_HELP_READYTORUN_GENERIC_HANDLE]
       cmp      qword ptr [rbx], rax
       sete     al
       movzx    rax, al

G_M000_IG03:                ;; offset=0x001C
       add      rsp, 48
       pop      rbx
       ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions