This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/46235] inefficient bittest code generation


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]