Skip to content

[JIT] Recognize when length is never negative for Span<T>::.ctor(void*, int32) #119466

@xtqqczze

Description

@xtqqczze
static unsafe Span<byte> M1(byte* p, int b) => new(p, (byte)b);
static unsafe Span<byte> M2(byte* p, byte b) => new(p, b);
; Core CLR 9.0.525.21509 on x64

C.M1(Byte*, Int32)
    L0000: sub rsp, 0x28
    L0004: movzx eax, r8b
    L0008: test eax, eax
    L000a: jl short L001a
    L000c: mov [rcx], rdx
    L000f: mov [rcx+8], eax
    L0012: mov rax, rcx
    L0015: add rsp, 0x28
    L0019: ret
    L001a: mov rax, 0x7ffebaa16d00
    L0024: call qword ptr [rax]
    L0026: int3

C.M2(Byte*, Byte)
    L0000: movzx eax, r8b
    L0004: mov [rcx], rdx
    L0007: mov [rcx+8], eax
    L000a: mov rax, rcx
    L000d: ret

codgen: sharplab.io, godbolt.org

References: #83248

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions