From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F08DC385C40F; Wed, 1 Sep 2021 21:25:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F08DC385C40F From: "deller at gmx dot de" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: deller at gmx 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: Message-ID: In-Reply-To: References: 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 21:25:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102162 --- 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 kno= w 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.=C2=A0 If type is char, o= ne gets > byte accesses.=C2=A0 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 : 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 32b= its with "extrw,s". So, only 16bits instead of 32bits are loaded from the address where "evil" is...=