public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108874] New: [10/11/12/13 Regression] Missing bswap detection
@ 2023-02-21 16:30 ktkachov at gcc dot gnu.org
  2023-02-21 16:53 ` [Bug tree-optimization/108874] " ktkachov at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: ktkachov at gcc dot gnu.org @ 2023-02-21 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108874
           Summary: [10/11/12/13 Regression] Missing bswap detection
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

If we look at the arm testcases in gcc.target/arm/rev16.c
typedef unsigned int __u32;

__u32
__rev16_32_alt (__u32 x)
{
  return (((__u32)(x) & (__u32)0xff00ff00UL) >> 8)
         | (((__u32)(x) & (__u32)0x00ff00ffUL) << 8);
}

__u32
__rev16_32 (__u32 x)
{
  return (((__u32)(x) & (__u32)0x00ff00ffUL) << 8)
         | (((__u32)(x) & (__u32)0xff00ff00UL) >> 8);
}

we should be able to generate rev16 instructions for aarch64 (and arm) i.e.
recognise a __builtin_bswap16 essentially.
GCC fails to do so and generates:
__rev16_32_alt:
        lsr     w1, w0, 8
        lsl     w0, w0, 8
        and     w1, w1, 16711935
        and     w0, w0, -16711936
        orr     w0, w1, w0
        ret
__rev16_32:
        lsl     w1, w0, 8
        lsr     w0, w0, 8
        and     w1, w1, -16711936
        and     w0, w0, 16711935
        orr     w0, w1, w0
        ret

whereas clang manages to recognise it all into:
__rev16_32_alt:                         // @__rev16_32_alt
        rev16   w0, w0
        ret
__rev16_32:                             // @__rev16_32
        rev16   w0, w0
        ret

does the bswap pass need some tweaking perhaps?

Looks like this worked fine with GCC 5 but broke in the GCC 6 timeframe so
marking as a regression

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-03-10 17:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 16:30 [Bug tree-optimization/108874] New: [10/11/12/13 Regression] Missing bswap detection ktkachov at gcc dot gnu.org
2023-02-21 16:53 ` [Bug tree-optimization/108874] " ktkachov at gcc dot gnu.org
2023-02-22  8:37 ` [Bug target/108874] " rguenth at gcc dot gnu.org
2023-02-22 10:39 ` ktkachov at gcc dot gnu.org
2023-02-22 10:53 ` rguenth at gcc dot gnu.org
2023-02-23 23:32 ` pinskia at gcc dot gnu.org
2023-02-25 19:51 ` pinskia at gcc dot gnu.org
2023-02-27  3:24 ` crazylht at gmail dot com
2023-02-27  4:39 ` pinskia at gcc dot gnu.org
2023-03-09 23:03 ` pinskia at gcc dot gnu.org
2023-03-10  0:39 ` pinskia at gcc dot gnu.org
2023-03-10  1:04 ` pinskia at gcc dot gnu.org
2023-03-10  6:04 ` pinskia at gcc dot gnu.org
2023-03-10 17:52 ` cvs-commit at gcc dot gnu.org
2023-03-10 17:54 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).