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

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions