Skip to content

Redundant nullcheck in ARR_LEN/IND on top of non-null array #84248

@EgorBo

Description

@EgorBo
void Foo()
{
    var arr = new int[10];
    var len = arr.Length;
}

Codegen:

; Method Program:Foo():this
G_M52879_IG01:              
       4883EC28             sub      rsp, 40
G_M52879_IG02:              
       48B928E4DFFCF87F0000 mov      rcx, 0x7FF8FCDFE428      ; int[]
       BA0A000000           mov      edx, 10
       E8384A865F           call     CORINFO_HELP_NEWARR_1_VC
       8B4008               mov      eax, dword ptr [rax+08H]  ;;  <----
G_M52879_IG03:              
       4883C428             add      rsp, 40
       C3                   ret      
; Total bytes of code: 32

and other patterns where JIT should be able to detect that ARR_LEN/IND is invoked on something known to be non-null, e.g.:

void Foo(int[] arr)
{
    if (arr != null)
    {
        var _ = arr.Length;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions