Skip to content

Bounds check around Span.IsEmpty is not elided #126857

@EgorBo

Description

@EgorBo
internal static void TryStripFirstCharAndTrailingSpaces(ref ReadOnlySpan<char> span, char value)
{
    if (!span.IsEmpty && span[0] == value)
    {
        Console.WriteLine("hey");
    }
}
; Assembly listing for method Bench:TryStripFirstCharAndTrailingSpaces(byref,char) (FullOpts)
G_M13170_IG01:
       sub      rsp, 40
G_M13170_IG02:
       mov      eax, dword ptr [rcx+0x08]
       test     eax, eax
       je       SHORT G_M13170_IG04
G_M13170_IG03:
       test     eax, eax
       je       SHORT G_M13170_IG07
       mov      rcx, bword ptr [rcx]
       movzx    rcx, word  ptr [rcx]
       movzx    rax, dx
       cmp      ecx, eax
       je       SHORT G_M13170_IG05
G_M13170_IG04:
       add      rsp, 40
       ret      
G_M13170_IG05:
       mov      rcx, 0x1AC49545008      ; 'hey'
G_M13170_IG06:
       add      rsp, 40
       tail.jmp [System.Console:WriteLine(System.String)]
G_M13170_IG07:
       call     CORINFO_HELP_RNGCHKFAIL
       int3     
; Total bytes of code 59

Expected behavior: no CORINFO_HELP_RNGCHKFAIL

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions