From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E75003858D29; Mon, 15 Feb 2021 09:43:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E75003858D29 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99101] optimization bug with -ffinite-loops Date: Mon, 15 Feb 2021 09:43:20 +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: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: version bug_status assigned_to keywords everconfirmed cf_reconfirmed_on component 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: Mon, 15 Feb 2021 09:43:21 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99101 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Version|og10 (devel/omp/gcc-10) |11.0 Status|UNCONFIRMED |ASSIGNED Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot = gnu.org Keywords| |wrong-code Ever confirmed|0 |1 Last reconfirmed| |2021-02-15 Component|c++ |tree-optimization --- Comment #1 from Richard Biener --- Confirmed. But note that C++ requires forward progress and thus technically the infinite loop invokes undefined behavior. CDDCE2 does (with -fno-tree-sra to show at_eof_) Assume loop 1 to be finite: it has an exit and -ffinite-loops is on. Removing basic block 14 [local count: 1073741824]: - comp_md_.at_eof_ =3D 0; [local count: 108447916235]: - # prephitmp_47 =3D PHI <1(2), 0(15)> - # prephitmp_22 =3D PHI <0(2), prephitmp_27(15)> - if (prephitmp_47 > 0) - goto ; [33.00%] - else - goto ; [67.00%] - - [local count: 35787812164]: - - [local count: 53412352861]: - # i_9 =3D PHI - # prephitmp_11 =3D PHI - if (prephitmp_11 !=3D 0) - goto ; [34.00%] - else - goto ; [66.00%] - - [local count: 11633210387]: - comp_md_.at_eof_ =3D 1; _14 =3D std::basic_ostream::operator<< (&cout, 1); _15 =3D _14->_vptr.basic_ostream; _16 =3D MEM[(long int *)_15 + -24B]; @@ -99,28 +88,12 @@ _43 =3D OBJ_TYPE_REF(_37;(const struct ctype)_23->6) (_23, 10); _10 =3D (int) _43; - [local count: 11628557050]: + [local count: 53407699675]: # prephitmp_24 =3D PHI <_13(8), 10(9), _10(10)> _21 =3D std::basic_ostream::put (_14, prephitmp_24); std::basic_ostream::flush (_21); - [local count: 53407699675]: - i_8 =3D i_9 + 1; - if (i_8 < prephitmp_47) - goto ; [33.00%] - else - goto ; [67.00%] - - [local count: 35783158878]: - pretmp_25 =3D comp_md_.at_eof_; - goto ; [100.00%] - - [local count: 17624540797]: - pretmp_2 =3D comp_md_.at_eof_; - goto ; [100.00%] - [local count: 108443262898]: - # prephitmp_27 =3D PHI goto ; [100.00%] } so the question would be why the std::cout << 1 call doesn't add its control dependence as necessary here. Hmm, and the reason is we have BB 5 only control dependent on itself. And I have a hunch that this boils down to post dominators being "wrong" here because of the missing edges to exit. Indeed if connecting infinite loops to exit in CD-DCE the bug is fixed.=