public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "m.frohiky at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/99847] New: Optimization breaks alignment on CPU32
Date: Wed, 31 Mar 2021 14:12:09 +0000	[thread overview]
Message-ID: <bug-99847-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-03-31 14:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 14:12 m.frohiky at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99847-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).