From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E4CF8388460D; Fri, 1 Apr 2022 11:06:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4CF8388460D From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/100810] [12 Regression] wrong code at -O1 and above on x86_64-linux-gnu since r12-397-gda9e6e63d1ae22e530ec7baf59f6ed028bf05776 Date: Fri, 01 Apr 2022 11:06:21 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 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: Fri, 01 Apr 2022 11:06:22 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100810 --- Comment #9 from Richard Biener --- Btw, while in the abstract machine sense for the testcase 'i' is never actu= ally read the SSA GIMPLE already exposes an uninitialized read of it: void k () { ... : a.9_3 =3D a; if (a.9_3 >=3D 0) goto ; [INV] else goto ; [INV] : i_25 =3D i_13 + 1; h.10_4 =3D h; _5 =3D h.10_4 + -1; h =3D _5; : # i_13 =3D PHI a.11_6 =3D a; if (a.11_6 !=3D 0) goto ; [INV] else goto ; [INV] that's because for while (a) { } which is not entered because 'a' is zero we have the PHI node for 'i' since the condition is part of the loop and SSA form requires us to represent the value of 'i' on the entry edge. That means those uses are not real uses and thus do not invoke undefined behavior (at the point of execution of the PHI node). That would be different from tem_2 =3D i_20(D); # tem_3 =3D PHI but copy propagation will turn this into the other case (but that would be conservatively OK). Note that for the testcase IVOPTs inserts the rewritten uses in a place where i is now used unconditionally turning if (a.9_15 >=3D 0) goto ; [59.00%] else goto ; [41.00%] [local count: 139545903]: goto ; [100.00%] [local count: 564526613]: i_17 =3D i_16 + 1; _19 =3D h_lsm.23_10 + -1; [local count: 634299566]: # i_16 =3D PHI # h_lsm.23_10 =3D PHI if (a.9_15 !=3D 0) goto ; [89.00%] else goto ; [11.00%] [local count: 69772953]: into if (a.9_15 >=3D 0) goto ; [59.00%] else goto ; [41.00%] [local count: 139545903]: goto ; [100.00%] [local count: 564526613]: i_17 =3D i_16 + 1; [local count: 634299566]: # i_16 =3D PHI _28 =3D (unsigned int) b.7_13; _41 =3D (unsigned int) i_24(D); _51 =3D _28 + _41; _22 =3D (unsigned int) i_16; _48 =3D -_22; _49 =3D _48 + _51; h_lsm.23_10 =3D (int) _49; if (a.9_15 !=3D 0) goto ; [89.00%] else goto ; [11.00%] [local count: 69772953]: when it eliminates the h_lsm.23 IV and rewrites it in terms of i.=