This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/46235] inefficient bittest code generation
- From: "chris.a.ferguson at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 03 Jun 2014 14:17:15 +0000
- Subject: [Bug rtl-optimization/46235] inefficient bittest code generation
- Auto-submitted: auto-generated
- References: <bug-46235-4 at http dot gcc dot gnu dot org/bugzilla/>
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