[Bug rtl-optimization/46235] inefficient bittest code generation
chris.a.ferguson at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Jun 3 14:17:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46235
--- Comment #5 from chris.a.ferguson at gmail dot com ---
This optimization opportunity is still being missed as of GCC 4.9.
Test cases:
bool IsBitSet1(unsigned char byte, int index)
{
return (byte & (1<<index)) != 0;
}
bool IsBitSet2(unsigned char byte, int index)
{
return (byte >> index) & 1;
}
>From GCC 4.9:
IsBitSet1(unsigned char, int):
mov ecx, esi
mov eax, 1
movzx edi, dil
sal eax, cl
test eax, edi
setne al
ret
IsBitSet2(unsigned char, int):
movzx eax, dil
mov ecx, esi
sar eax, cl
and eax, 1
ret
>From Clang 3.3:
IsBitSet1(unsigned char, int):
btl %esi, %edi
setb %al
ret
IsBitSet2(unsigned char, int):
btl %esi, %edi
setb %al
ret
More information about the Gcc-bugs
mailing list