Skip to content

ArrBnds assertion with Phi index doesn't remove bounds checks. #121617

Closed

Description

@EgorBo
static void Test(Span<int> dst, bool cond)
{
    dst[cond ? 35 : 31] = 11;
    dst[10] = 22;
    dst[11] = 33;
}

Codegen:

; Method Progream:Test(System.Span`1[int],bool) (FullOpts)
G_M50183_IG01:
       sub      rsp, 40
G_M50183_IG02:
       mov      eax, 35
       mov      r8d, 31
       test     dl, dl
       cmove    eax, r8d
       cmp      eax, dword ptr [rcx+0x08]
       jae      SHORT G_M50183_IG04
       mov      rdx, bword ptr [rcx]
       mov      dword ptr [rdx+4*rax], 11
       cmp      dword ptr [rcx+0x08], 10
       jbe      SHORT G_M50183_IG04
       mov      rax, bword ptr [rcx]
       mov      dword ptr [rax+0x28], 22
       cmp      dword ptr [rcx+0x08], 11
       jbe      SHORT G_M50183_IG04
       mov      rax, bword ptr [rcx]
       mov      dword ptr [rax+0x2C], 33
G_M50183_IG03:  ;; offset=0x0044
       add      rsp, 40
       ret      
G_M50183_IG04:
       call     CORINFO_HELP_RNGCHKFAIL
       int3     
; Total bytes of code: 79

Redundant bounds checks aren't removed. I actually hit it when I was trying to replace unsafe code with safe in the BCL.

Activity

  1. added
    untriaged
    on Nov 14, 2025
  2. added
    area-CodeGen-coreclr
    and removed
    untriaged
    on Nov 14, 2025
  3. self-assigned this
    on Nov 14, 2025
  4. added this to the 11.0.0 milestone on Nov 14, 2025
  5. dotnet-policy-service commented on Nov 14, 2025

    @dotnet-policy-service
    Contributor

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

  6. locked and limited conversation to collaborators on Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrreduce-unsafe

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions