Skip to content

JIT: Optimize "X & 1 == 0" to "X & 1" #61412

Closed
@EgorBo

Description

@EgorBo
static bool Test(int x) => (x & 1) == 0;

Just a good first issue for anyone interested in contributing to CLR JIT.

Current codegen:

test     cl, 1
sete     al
movzx    rax, al
ret

Expected codegen:

mov      eax, ecx
and      eax, 1
ret

I noticed it when I was trying to implement a faster IsNegative for floats:

static bool IsNegative(double x) => 
    (Sse2.MoveMask(Vector128.CreateScalarUnsafe(x)) & 1) != 0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIgood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions