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
Repro:
x64 codegen:
Note the
movsxinstruction on L001a. Ideally this would be folded into the instruction above to produce the single instructionmovsx eax, byte ptr [rax + rdx].category:performance
theme:codegen
skill-level:intermediate
cost:medium
impact:medium