From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4F8283858D28; Fri, 5 Nov 2021 12:52:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F8283858D28 From: "felix at breitweiser dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103100] New: unaligned access generated when zero-initializing large locals with SIMD-instructions and -O2 -mstrict-align Date: Fri, 05 Nov 2021 12:52:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: felix at breitweiser dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2021 12:52:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103100 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=3D51738&action=3Dedit source code that generates the faulty assembly when zero-intializing large local variables, gcc 11.2 (with -O2 and -O3) us= es SIMD registers to store a pair of 16-byte registers at once into memory. Wh= en doing so, gcc can generate code that does not access memory on a 16-byte aligned boundary, even though the aarch64 architecture requires memory acce= sses to be 16-byte aligned when using the full 16-byte SIMD registers. This happ= ens with -mstrict-align enabled. For example: static void (*use)(unsigned char*); // to suppress optimizations extern "C" void _start() { unsigned char t2[216]=3D{}; use(t2); } when compiled with "gcc -save-temps -O2 -mstrict-align" generates the follo= wing assembly: _start: stp x29, x30, [sp, #-240]!// assuming sp is aligned to 16-bytes here=20 mov x1, #0x0 movi v0.4s, #0x0 add x2, sp, #0x28 // the value in x2 is 8-byte aligned, but not= =20 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=3D71727 and even t= hough that is marked as fixed, this issue persists in gcc 11.2=