Skip to content

Transform (x1 == x2) && (y1 == y2) into ((x1 - x2) | (y1 - y2)) == 0 for (u)ints, (u)longs #36620

Open
@hypeartist

Description

@hypeartist

Codegen for:

public static bool Equal(int x1, int x2, int y1, int y2) => (x1 == x2) && (y1 == y2);

    L0000: cmp ecx, edx
    L0002: jne short L000e
    L0004: cmp r8d, r9d
    L0007: sete al
    L000a: movzx eax, al
    L000d: ret
    L000e: xor eax, eax
    L0010: ret

Codegen for:

public static bool Equal(int x1, int x2, int y1, int y2) => ((x1 - x2) | (y1 - y2)) == 0;

    L0000: sub ecx, edx
    L0002: sub r8d, r9d
    L0005: or ecx, r8d
    L0008: sete al
    L000b: movzx eax, al
    L000e: ret

PS: what is the purpose for movzx eax, al in both cases? According to godbolt neither msvc nor clang nor gcc emit it.

category:cq
theme:expression-opts
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 SuperPMIoptimizationtenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions