From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3A18E3858D39; Thu, 5 Jan 2023 17:10:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A18E3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672938606; bh=zoTDMb84DlEWEBRQRZO0q5ccTh9eMg7tpg6YOQv2Pyw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hft68nN78BFQTisDUmXNwClfBRwoTDYBv4mVzKZKyXNHLSCk0UcaJzIAMGQYGHtrR 1DZrgfbxXRCz9My9v0sTxJozJHLCFESJS5A5KUrmTSUDcTmku1CahOXep8F/7ZYsss SuYU/T59Qi4nFY5MLaclBh28Zsm8kkHheSeEf7GQ= From: "segher at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108298] Wrong optimization of volatile access from gcc 11 and beyond Date: Thu, 05 Jan 2023 17:10:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: segher at gcc dot gnu.org X-Bugzilla-Status: NEW 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108298 --- Comment #5 from Segher Boessenkool --- This is not x86-specific. Like on powerpc64 we get addi 3,3,3 # 11 [c=3D4 l=3D4] *addsi3/1 extsw 3,3 # 17 [c=3D4 l=3D4] extendsidi2/1 blr # 25 [c=3D4 l=3D4] simple_return Before RTL all is fine still: int foo (int a, int b, int c) { int _1; int _2; ;; basic block 2, loop depth 0 ;; pred: ENTRY _1 =3D a_3(D) + 1; b =3D _1; _2 =3D{v} MEM[(volatile int *)&b]; a_6 =3D _2 + 2; return a_6; ;; succ: EXIT } But it is expanded to something that is not going through memory: ;; _2 =3D{v} MEM[(volatile int *)&b]; (insn 10 9 0 (set (reg:SI 118 [ _2 ]) (subreg/s/u:SI (reg/v:DI 121 [ b+-4 ]) 4)) "108298.c":10:9 -1 (nil))=