From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 81022385841C; Sat, 18 Sep 2021 18:35:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81022385841C From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102402] Seemingly suboptimal optimization of jmp/cmovcc for conditionally loading constants Date: Sat, 18 Sep 2021 18:35:05 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: everconfirmed component cf_reconfirmed_on bug_status 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: Sat, 18 Sep 2021 18:35:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102402 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Component|target |tree-optimization Last reconfirmed| |2021-09-18 Status|UNCONFIRMED |NEW --- Comment #1 from Andrew Pinski --- Confirmed, note the best code is generated by: void ClearModM1(struct MusicPlayerTrack *track, uint8_t modT) { int t =3D0; if (track->modT =3D=3D 0) t =3D 3; else t =3D 12; track->flags |=3D t; } This is then a gimple level issue where: if (_1 =3D=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: _3 =3D pretmp_6 | 3; goto ; [100.00%] [local count: 536870913]: _5 =3D pretmp_6 | 12; [local count: 1073741824]: # cstore_12 =3D PHI <_3(3), _5(4)> is not transformed into: if (track->modT =3D=3D 0) t =3D 3; else t =3D 12; cstore_12 =3D pretmp_6 | t; There is also a sinking issue though I don't know if has a wider effect (and does not matter in this case really). Take: void ClearModM1(struct MusicPlayerTrack *track, uint8_t modT) { int t =3D0; int t2 =3D track->modT; int t1 =3D track->flags; if (t2 =3D=3D 0) t =3D 3; else t =3D 12; track->flags =3D t1|t; } The load for track->flags is not sunk after the if.=