Skip to content

JIT perf: ldind.u1 followed by conv.i1 results in suboptimal codegen #69472

Description

@GrabYourPitchforks

Repro:

public static int Foo(int i)
{
    ReadOnlySpan<byte> span = new byte[] { 1, 2, 0xFF };
    return (sbyte)span[i];
}

x64 codegen:

C.Foo(Int32)
    L0000: sub rsp, 0x28
    L0004: cmp ecx, 3
    L0007: jae short L0023
    L0009: movsxd rax, ecx
    L000c: mov rdx, 0x1a13a680930
    L0016: movzx eax, byte ptr [rax+rdx]
    L001a: movsx rax, al
    L001e: add rsp, 0x28
    L0022: ret
    L0023: call 0x00007ffc4814ec40
    L0028: int3

Note the movsx instruction on L001a. Ideally this would be folded into the instruction above to produce the single instruction movsx eax, byte ptr [rax + rdx].

category:performance
theme:codegen
skill-level:intermediate
cost:medium
impact:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issue

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions