public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/103100] New: unaligned access generated when zero-initializing large locals with SIMD-instructions and -O2 -mstrict-align
@ 2021-11-05 12:52 felix at breitweiser dot de
  2021-11-05 12:58 ` [Bug target/103100] " pinskia at gcc dot gnu.org
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: felix at breitweiser dot de @ 2021-11-05 12:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103100
           Summary: unaligned access generated when zero-initializing
                    large locals with SIMD-instructions and -O2
                    -mstrict-align
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix at breitweiser dot de
  Target Milestone: ---

Created attachment 51738
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51738&action=edit
source code that generates the faulty assembly

when zero-intializing large local variables, gcc 11.2 (with -O2 and -O3) uses
SIMD registers to store a pair of 16-byte registers at once into memory. When
doing so, gcc can generate code that does not access memory on a 16-byte
aligned boundary, even though the aarch64 architecture requires memory accesses
to be 16-byte aligned when using the full 16-byte SIMD registers. This happens
with -mstrict-align enabled.

For example:

static void (*use)(unsigned char*); // to suppress optimizations

extern "C" void _start() {
    unsigned char t2[216]={};
    use(t2);
}

when compiled with "gcc -save-temps -O2 -mstrict-align" generates the following
assembly:
_start:
        stp     x29, x30, [sp, #-240]!// assuming sp is aligned to 16-bytes
here 
        mov     x1, #0x0
        movi    v0.4s, #0x0
        add     x2, sp, #0x28 // the value in x2 is 8-byte aligned, but not 
                                 16-byte aligned
        mov     x29, sp
        stp     xzr, xzr, [sp, #24]
        add     x0, sp, #0x18
        stp     q0, q0, [x2] // x2 is not 16-byte aligned, so the store is not
                                aligned
        add     x2, sp, #0x48
        str     xzr, [sp, #232]
        stp     q0, q0, [x2]
        add     x2, sp, #0x68
        stp     q0, q0, [x2]
        add     x2, sp, #0x88
        stp     q0, q0, [x2]
        add     x2, sp, #0xa8
        stp     q0, q0, [x2]
        add     x2, sp, #0xc8
        stp     q0, q0, [x2]
        blr     x1
        ldp     x29, x30, [sp], #240
        ret

I have seen https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71727 and even though
that is marked as fixed, this issue persists in gcc 11.2

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

end of thread, other threads:[~2023-11-30 13:49 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 12:52 [Bug target/103100] New: unaligned access generated when zero-initializing large locals with SIMD-instructions and -O2 -mstrict-align felix at breitweiser dot de
2021-11-05 12:58 ` [Bug target/103100] " pinskia at gcc dot gnu.org
2021-11-05 13:17 ` pinskia at gcc dot gnu.org
2021-11-05 13:21 ` [Bug target/103100] [11/12 Regression] unaligned access generated with memset or {} " pinskia at gcc dot gnu.org
2021-11-05 13:26 ` pinskia at gcc dot gnu.org
2021-11-05 13:27 ` pinskia at gcc dot gnu.org
2021-11-05 13:35 ` rguenth at gcc dot gnu.org
2021-11-05 13:38 ` pinskia at gcc dot gnu.org
2021-11-06  5:26 ` pinskia at gcc dot gnu.org
2021-11-18  8:50 ` pinskia at gcc dot gnu.org
2021-11-19  1:55 ` pinskia at gcc dot gnu.org
2022-01-26  2:30 ` pinskia at gcc dot gnu.org
2022-04-21  7:50 ` rguenth at gcc dot gnu.org
2022-06-09 10:28 ` [Bug target/103100] [11/12/13 " pinskia at gcc dot gnu.org
2023-01-19 13:28 ` rguenth at gcc dot gnu.org
2023-01-20 13:59 ` rearnsha at gcc dot gnu.org
2023-01-23  7:29 ` felix at breitweiser dot de
2023-01-23  7:37 ` sam at gentoo dot org
2023-01-31 17:49 ` pinskia at gcc dot gnu.org
2023-01-31 17:51 ` pinskia at gcc dot gnu.org
2023-01-31 18:24 ` rearnsha at gcc dot gnu.org
2023-02-10  3:54 ` pinskia at gcc dot gnu.org
2023-03-24 12:09 ` pinskia at gcc dot gnu.org
2023-04-05 19:25 ` pinskia at gcc dot gnu.org
2023-05-29 10:06 ` [Bug target/103100] [11/12/13/14 " jakub at gcc dot gnu.org
2023-09-20 13:53 ` wilco at gcc dot gnu.org
2023-11-30 13:49 ` cvs-commit 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).