public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106513] New: bswap is incorrectly generated
@ 2022-08-03 11:56 kristerw at gcc dot gnu.org
  2022-08-03 12:12 ` [Bug tree-optimization/106513] " schwab@linux-m68k.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: kristerw at gcc dot gnu.org @ 2022-08-03 11:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106513
           Summary: bswap is incorrectly generated
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
  Target Milestone: ---

GCC may incorrectly generate bswap instructions for code not doing a correct
swap. This can be seen by running the function from testsuite/gcc.dg/pr40501.c
as

typedef long int int64_t;

__attribute__((noinline)) int64_t
swap64 (int64_t n)
{
  return (((n & (((int64_t) 0xff) )) << 56) |
          ((n & (((int64_t) 0xff) << 8)) << 40) |
          ((n & (((int64_t) 0xff) << 16)) << 24) |
          ((n & (((int64_t) 0xff) << 24)) << 8) |
          ((n & (((int64_t) 0xff) << 32)) >> 8) |
          ((n & (((int64_t) 0xff) << 40)) >> 24) |
          ((n & (((int64_t) 0xff) << 48)) >> 40) |
          ((n & (((int64_t) 0xff) << 56)) >> 56));
}

int main (void)
{
  volatile int64_t n = 0x8000000000000000l;

  if (swap64(n) != 0xffffffffffffff80l)
    __builtin_abort ();

  return 0;
}

This fails at -Os and higher optimization levels.

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

end of thread, other threads:[~2022-10-14 10:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 11:56 [Bug tree-optimization/106513] New: bswap is incorrectly generated kristerw at gcc dot gnu.org
2022-08-03 12:12 ` [Bug tree-optimization/106513] " schwab@linux-m68k.org
2022-08-03 12:41 ` kristerw at gcc dot gnu.org
2022-08-05 22:15 ` [Bug tree-optimization/106513] [10/11/12/13 Regression] bswap pass misses that >>56 for signed types can be replicate the sign bit pinskia at gcc dot gnu.org
2022-08-10 13:43 ` rguenth at gcc dot gnu.org
2022-08-10 13:51 ` rguenth at gcc dot gnu.org
2022-08-10 14:39 ` cvs-commit at gcc dot gnu.org
2022-08-10 14:40 ` cvs-commit at gcc dot gnu.org
2022-10-11 13:04 ` [Bug tree-optimization/106513] [10/11 " cvs-commit at gcc dot gnu.org
2022-10-14 10:47 ` [Bug tree-optimization/106513] [10 " cvs-commit at gcc dot gnu.org
2022-10-14 10:48 ` rguenth 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).