public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/99847] New: Optimization breaks alignment on CPU32
@ 2021-03-31 14:12 m.frohiky at gmail dot com
  2021-03-31 14:32 ` [Bug target/99847] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: m.frohiky at gmail dot com @ 2021-03-31 14:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99847
           Summary: Optimization breaks alignment on CPU32
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.frohiky at gmail dot com
  Target Milestone: ---

For CPU32 architecture optimizes two byte accesses into a single word access,
without any regard that the original array may be unaligned.

So this code:

void ntoh(const uint8_t *idata, uint16_t *odata) {
    *odata = ((uint16_t)idata[0] << 8) | idata[1];
}

Compiled with -Os or -O2 produces:

        move.l 4(%sp),%a1
        move.l 8(%sp),%a0
        move.w (%a1),(%a0)
        rts

And if idata (address in register a1) is not aligned, the CPU will crash.

The compiler I'm using is m68k-linux-gnu-gcc (g++ has the same problem) which
comes from Debian repository. The exact version is "(Debian 10.2.1-6) 10.2.1
20210110"

Even if it's relying on exception handler to handle the unaligned data it makes
no sense because it's sooo much slower.

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

end of thread, other threads:[~2021-04-01 14:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 14:12 [Bug rtl-optimization/99847] New: Optimization breaks alignment on CPU32 m.frohiky at gmail dot com
2021-03-31 14:32 ` [Bug target/99847] " rguenth at gcc dot gnu.org
2021-03-31 14:40 ` m.frohiky at gmail dot com
2021-03-31 18:21 ` mikpelinux at gmail dot com
2021-03-31 21:11 ` m.frohiky at gmail dot com
2021-04-01 14:14 ` m.frohiky at gmail dot com

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).