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

            Bug ID: 99520
           Summary: Failure to detect bswap pattern
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

#include <stdint.h>

 uint32_t endian_fix32( uint32_t x ){
    return (x<<24) + ((x<<8)&0xff0000) + ((x>>8)&0xff00) + (x>>24);

}

For aarch64 clang manages to optimise it to:
endian_fix32(unsigned int):                      // @endian_fix32(unsigned int)
        rev     w0, w0
        ret

GCC doesn't:
endian_fix32(unsigned int):
        lsl     w1, w0, 8
        lsr     w2, w0, 8
        and     w2, w2, 65280
        lsr     w3, w0, 24
        and     w1, w1, 16711680
        add     w0, w3, w0, lsl 24
        orr     w1, w1, w2
        add     w0, w1, w0
        ret

Is there something missing in the bswap pass?

Reply via email to