Closed
Description
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