public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/114046] New: Aarch64: Os,O1,02,O3 optimisations generates unaligned access in short members of structure
@ 2024-02-22 8:47 stephane at syena dot net
2024-02-22 8:52 ` [Bug driver/114046] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: stephane at syena dot net @ 2024-02-22 8:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114046
Bug ID: 114046
Summary: Aarch64: Os,O1,02,O3 optimisations generates unaligned
access in short members of structure
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: driver
Assignee: unassigned at gcc dot gnu.org
Reporter: stephane at syena dot net
Target Milestone: ---
The issuer is reproduced with the following (simplified) code:
struct test {
short a;
short b;
short c;
};
void function( struct test *p, int n ) {
p->a = n;
p->b = 0;
p->c = 0;
}
# gcc -Os -S unaligned_store.c && cat unaligned_store.s
.arch armv8-a
.file "unaligned_store.c"
.text
.align 2
.global function
.type function, %function
function:
strh w1, [x0]
str wzr, [x0, 2] <<<<<<<<< Alignment fault
ret
.size function, .-function
.ident "GCC: (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1
20231009"
The second instruction generates an unaligned 32-bits store at a 16-bits
aligned address.
I suspect that the optimizer detects that consecutive short members b and c are
both set to zero and group them to generate a single long access but somehow
fails to detect that the resulting access is not aligned.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug driver/114046] Aarch64: Os,O1,02,O3 optimisations generates unaligned access in short members of structure
2024-02-22 8:47 [Bug driver/114046] New: Aarch64: Os,O1,02,O3 optimisations generates unaligned access in short members of structure stephane at syena dot net
@ 2024-02-22 8:52 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-22 8:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114046
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You need to use -mstrict-align here if you are writing (early) firmware where
the page table is not setup and marked as unaligned is ok for normal memory.
If you writing to non-normal memory, you need to use the volatile keyword so
GCC does not produce unaligned memory access in general.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-22 8:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 8:47 [Bug driver/114046] New: Aarch64: Os,O1,02,O3 optimisations generates unaligned access in short members of structure stephane at syena dot net
2024-02-22 8:52 ` [Bug driver/114046] " 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).