https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93328

Paco Arjonilla <pacoarjonilla at yahoo dot es> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pacoarjonilla at yahoo dot es

--- Comment #2 from Paco Arjonilla <pacoarjonilla at yahoo dot es> ---
Using shifts and bitwise does not optimize either in GCC master, but it does
optimize in CLang.

Take this code:

#include <cstdint>
using type = std::uint32_t;
type foo(type v){
    type r  = (v << 24) & 0xFF000000;
         r += (v << 8)  & 0x00FF0000;
         r += (v >> 8)  & 0x0000FF00;
         r += (v >> 24) & 0x000000FF;
    return r;
}

CLang assembler output: ( optimize with -O2 )

        mov     eax, edi
        bswap   eax
        ret


GCC master assembler output: ( optimize with -O2 )
        mov     eax, edi
        mov     edx, edi
        shr     eax, 24
        sal     edx, 24
        add     edx, eax
        mov     eax, edi
        shr     edi, 8
        sal     eax, 8
        and     edi, 65280
        and     eax, 16711680
        add     eax, edx
        add     eax, edi
        ret

Reply via email to