From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CB5013858D35; Fri, 3 Sep 2021 00:59:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB5013858D35 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98908] Failure to optimize arithmetic involving struct members into operating on the entire struct Date: Fri, 03 Sep 2021 00:59:28 +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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 9.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status target_milestone resolution 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: Fri, 03 Sep 2021 00:59:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98908 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|WAITING |RESOLVED Target Milestone|--- |9.0 Resolution|--- |FIXED --- Comment #7 from Andrew Pinski --- (In reply to Gabriel Ravier from comment #6) > Also the second example wasn't misoptimized, on the contrary it was the m= ost > reasonable portable function I could write that would work equivalently to > the first *and* that GCC would optimize ideally. GCC 7.1.0 produces: f(reg): .LFB0: .cfi_startproc mov edx, edi xor eax, eax mov ecx, edi and edx, -2 mov al, dl movzx edx, ch and edx, -128 mov ah, dl ret f1(reg): .LFB1: .cfi_startproc and di, -32514 xor eax, eax movzx edx, di mov al, dil sar edx, 8 mov ah, dl ret f is your first example and f1 is the second. As you can see GCC before GCC 8 did neither. In GCC 8, the second function produces: _1 =3D x.l; _2 =3D (signed short) _1; _3 =3D x.h; _4 =3D (int) _3; _5 =3D _4 << 8; _6 =3D (signed short) _5; _7 =3D _2 | _6; _8 =3D (short unsigned int) _7; tmp_14 =3D _8 & 33022; MEM[(unsigned char *)&D.2500] =3D tmp_14; And is only opimitized in GCC 9 with bswap producing what I mentioned before So fixed for GCC 9.=