Skip to content

JIT sometimes emits unnecessary movsxd instructions when performing logical operations against consts #32089

@GrabYourPitchforks

Description

@GrabYourPitchforks

Repro, courtesy sharplab:

public static bool CompareAgainstConstInt(int a) {
    return (a & 0x40) == 0;
}
    
public static bool CompareAgainstConstUInt(int a) {
    return (a & 0x40u) == 0;
}
; C.CompareAgainstConstInt(Int32)
    L0000: test cl, 0x40
    L0003: setz al
    L0006: movzx eax, al
    L0009: ret

; C.CompareAgainstConstUInt(Int32)
    L0000: movsxd rax, ecx   ; <-- this is unnecessary
    L0003: test al, 0x40
    L0005: setz al
    L0008: movzx eax, al
    L000b: ret

category:cq
theme:optimization
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