Skip to content

Missed optimization for bitset based equality #65120

Closed
@bmaurer

Description

@bmaurer

https://godbolt.org/z/nTseoW9z1

bool test(unsigned long long x) {
    auto mask = x & 0xf;
    return (mask == 10 || mask == 1 || mask == 2);
}

clang generates:

test(unsigned long long):                               # @test(unsigned long long)
        and     edi, 15
        cmp     rdi, 11
        setb    cl
        mov     eax, 1030
        bt      eax, edi
        setb    al
        and     al, cl
        ret

the comparison against 11 is unnecessary given the range of the mask operation. GCC emits shorter code:

test(unsigned long long):
        and     edi, 15
        mov     eax, 1030
        bt      rax, rdi
        setc    al
        ret

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions