Skip to content

Unnecessary sign-extension with bitwise ANDΒ #119962

@xtqqczze

Description

@xtqqczze
static nint M1(int value) {
    return value & 1;
}
static nint M2(int value) {
    return (nint)((uint)value & 1);
}
// coreclr trunk-20250921+80fb00f580f5b2353ff3a8aa78c5b5fd3f275a34

C:M1(int):nint (FullOpts):
       and      edi, 1
       movsxd   rax, edi
       ret      

C:M2(int):nint (FullOpts):
       and      edi, 1
       mov      eax, edi
       ret      

godbolt.org

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions