Skip to content

JIT: Optimize "x & cns == cns" pattern #101000

@EgorBo

Description

@EgorBo

Noticed in #100999:

void Foo(int x)
{
    if ((x & 0xC000000) == 0xC000000)
        Console.WriteLine();
}

Codegen on arm64:

            and     w0, w1, #0xC000000
            mov     w1, #0xC000000
            cmp     w0, w1
            bne     G_M37282_IG05

Expected codegen:

            mov     w1, #0xC000000
            bics    wzr, w8, w1
            bne     G_M37282_IG05

x64 is suboptimal for it as well, current codegen:

       and      edx, 0xC000000
       cmp      edx, 0xC000000
       jne      SHORT G_M37282_IG04

^ should be not + test.

Metadata

Metadata

Assignees

No one assigned

    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 contributorsin-prThere is an active PR which will close this issue when it is merged

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions