From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ACAD7385743C; Wed, 1 Sep 2021 16:52:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACAD7385743C From: "danglin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102162] New: Byte-wise access optimized away at -O1 and above Date: Wed, 01 Sep 2021 16:52:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: danglin at gcc dot gnu.org 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 cc target_milestone cf_gcchost cf_gcctarget cf_gccbuild 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: Wed, 01 Sep 2021 16:52:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102162 Bug ID: 102162 Summary: Byte-wise access optimized away at -O1 and above Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: danglin at gcc dot gnu.org CC: helge.deller at sap dot com Target Milestone: --- Host: hppa*-*-linux* Target: hppa*-*-linux* Build: hppa*-*-linux* Created attachment 51394 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51394&action=3Dedit Test case The packed attribute is used in Linux v5.14 to request byte-wise access to unaligned data. This is important on hppa as loads and stores require strict alignment. The attached test program is miscompiled at -O1 and above. The byte-wise accesses are optimized to a single ldw instruction during RTL expansion: .LEVEL 2.0w .text .align 8 .globl test .type test, @function test: .PROC .CALLINFO FRAME=3D0,NO_CALLS .ENTRY addil LT'output_len,%r27 ldd RT'output_len(%r1),%r28 ldw 0(%r28),%r28 bve (%r2) extrd,s %r28,63,32,%r28 .EXIT .PROCEND .size test, .-test .globl output_len .section .bss .type output_len, @object .size output_len, 4 .align 1 output_len: .block 4 .ident "GCC: (GNU) 10.3.0" This faults when output_len is not aligned on a word boundary. Not sure, but problem may be the test-unaligned.c.027t.einline pass: ;; Function get_unaligned_le32 (get_unaligned_le32, funcdef_no=3D0, decl_uid=3D1506, cgraph_uid=3D1, symbol_order=3D1) Iterations: 0 get_unaligned_le32 (const void * p) { const struct { u32 x; } * __pptr; u32 _4; : __pptr_2 =3D p_1(D); _4 =3D __pptr_2->x; return _4; } ;; Function test (test, funcdef_no=3D1, decl_uid=3D1512, cgraph_uid=3D2, symbol_order=3D2) Iterations: 1 Symbols to be put in SSA form { D.1520 D.1524 } Incremental SSA update started at block: 0 Number of blocks in CFG: 5 Number of blocks to update: 4 ( 80%) Merging blocks 2 and 4 Merging blocks 2 and 3 test () { u32 D.1524; unsigned int _1; unsigned int _3; int _4; : _3 =3D MEM[(const struct *)&output_len].x; _5 =3D _3; _1 =3D _5; _4 =3D (int) _1; return _4; } Ultimately, the MEM gets expanded to the ldw.=