public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "deller at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102162] Byte-wise access optimized away at -O1 and above
Date: Wed, 01 Sep 2021 21:25:56 +0000	[thread overview]
Message-ID: <bug-102162-4-EtVVBJm2BT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102162-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from deller at gmx dot de ---
On 9/1/21 11:19 PM, dave.anglin at bell dot net wrote:
>> I think the problem with your testcase is, that the compiler doesn't know the
>> alignment of the parameter "p" in your f_unaligned() function.
>> So it will generate byte-accesses.
> I think it's the type rather than the alignment.  If type is char, one gets
> byte accesses.  If type is short, one gets 16-bit accesses.
>
> The alignment is being ignored.

You are right.
It's even worse!

short evil;
int f_unaligned2(void)
{ return get_unaligned(&evil); }

gives:
00000000 <f_unaligned2>:
    0:   2b 60 00 00     addil L%0,dp,r1
    4:   44 3c 00 00     ldh 0(r1),ret0
    8:   e8 40 c0 00     bv r0(rp)
    c:   d3 9c 1f f0     extrw,s ret0,31,16,ret0

The "ldh" loads only the first two bytes, and extends it into the upper 32bits
with "extrw,s".
So, only 16bits instead of 32bits are loaded from the address where "evil"
is...

  parent reply	other threads:[~2021-09-01 21:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 16:52 [Bug tree-optimization/102162] New: " danglin at gcc dot gnu.org
2021-09-01 18:52 ` [Bug tree-optimization/102162] " danglin at gcc dot gnu.org
2021-09-01 20:14 ` arnd at linaro dot org
2021-09-01 20:52 ` deller at gmx dot de
2021-09-01 20:56 ` dave.anglin at bell dot net
2021-09-01 21:08 ` dave.anglin at bell dot net
2021-09-01 21:15 ` deller at gmx dot de
2021-09-01 21:19 ` dave.anglin at bell dot net
2021-09-01 21:25 ` deller at gmx dot de [this message]
2021-09-01 21:29 ` deller at gmx dot de
2021-09-01 21:48 ` pinskia at gcc dot gnu.org
2021-09-01 21:51 ` [Bug middle-end/102162] " pinskia at gcc dot gnu.org
2021-09-01 21:52 ` pinskia at gcc dot gnu.org
2021-09-01 22:35 ` dave.anglin at bell dot net
2021-09-01 22:46 ` dave.anglin at bell dot net
2021-09-01 22:56 ` pinskia at gcc dot gnu.org
2021-09-01 23:19 ` pinskia at gcc dot gnu.org
2021-09-01 23:21 ` pinskia at gcc dot gnu.org
2021-09-01 23:29 ` pinskia at gcc dot gnu.org
2021-09-01 23:45 ` pinskia at gcc dot gnu.org
2021-09-01 23:55 ` pinskia at gcc dot gnu.org
2021-09-02  0:02 ` dave.anglin at bell dot net
2021-09-02  0:19 ` pinskia at gcc dot gnu.org
2021-09-02  0:23 ` pinskia at gcc dot gnu.org
2021-09-02  0:47 ` dave.anglin at bell dot net
2021-09-02  0:49 ` pinskia at gcc dot gnu.org
2021-09-02  3:33 ` pinskia at gcc dot gnu.org
2021-09-02  7:12 ` rguenth at gcc dot gnu.org
2021-09-02  9:01 ` arnd at linaro dot org
2021-09-02  9:41 ` deller at gmx dot de
2021-09-02  9:52 ` pinskia at gcc dot gnu.org
2021-09-02 13:59 ` deller at gmx dot de
2021-09-02 14:00 ` deller at gmx dot de
2021-09-03 23:25 ` deller at gmx dot de

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-102162-4-EtVVBJm2BT@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).