Skip to content

Array variance checks are not optimized away for types known to be not arrays #97000

Open

Description

Description

It appears that array variance checks against e.g. List<T> are not optimized away for patterns like (obj)list is int[].

Configuration

.NET 8.0.100

Regression?

No

Analysis

Given below pattern

static bool Foo(List<int> l)
{
    return (object)l is int[];
}

The produced asm is

G_M39343_IG01:  ;; offset=0x0000
       push     rax
G_M39343_IG02:  ;; offset=0x0001
       mov      rsi, rdi
       mov      rdi, 0x7FDDF17D91D0      ; int[]
       call     [CORINFO_HELP_ISINSTANCEOFARRAY]
       test     rax, rax
       setne    al
       movzx    rax, al
G_M39343_IG03:  ;; offset=0x001D
       add      rsp, 8
       ret      

instead of

       xor rax, rax
       ret

Should this pattern get optimized, this will allow to update e.g. Enumerable.SequenceEquals in such a way that type tests are optimized away and it directly forwards to CollectionsMarshal.AsSpan(list).SequenceEquals(...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions