Skip to content

JIT produces unoptimized codegen for indirect byte comparisons against a register #33504

Closed
@GrabYourPitchforks

Description

@GrabYourPitchforks

Repro code:

public static void Test(ref byte theRef, byte b) {
    if (theRef == b)
    {
        Console.WriteLine("Hi!");
    }
}

Actual codegen:

; Test(Byte ByRef, Byte)
    L0000: movzx ecx, byte [rcx]
    L0003: movzx eax, dl
    L0006: cmp ecx, eax
    L0008: jnz L0024
    L000a: mov rcx, 0x282bd891e88
    L0014: mov rcx, [rcx]
    L0017: mov rax, 0x7ffac922d5e8
    L0021: jmp rax
    L0024: ret

Expected behavior:

I would expect those first three instructions to be combined into a single cmp byte ptr [rcx], dl instruction.

category:cq
theme:codegen
skill-level:intermediate
cost:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions