From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6233E395040D; Wed, 24 Feb 2021 14:20:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6233E395040D From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99101] optimization bug with -ffinite-loops Date: Wed, 24 Feb 2021 14:20:33 +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: 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: Wed, 24 Feb 2021 14:20:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99101 --- Comment #9 from Richard Biener --- Another fix for the finite-loop issue would be to avoid considering loops n= ot post-dominated by the exit block as finite. Like with the imperfect diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 3817ec423e7..388c03ee6fc 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2865,6 +2865,16 @@ finite_loop_p (class loop *loop) FOR_EACH_VEC_ELT (exits, i, ex) if (!(ex->flags & (EDGE_EH | EDGE_ABNORMAL | EDGE_FAKE))) { + /* But do not count noreturn regions as exit. + ??? This is a to simple check, we'd have to either + use post-dominance by the exit block (which isn't + computed) or a DFS walk. See PR99101 where the + the fact that control dependence (and post-dominance) + is not well-defined for not backward reachable regions + causes issues otherwise. */ + if (ex->dest->index !=3D EXIT_BLOCK + && EDGE_COUNT (ex->dest->succs) =3D=3D 0) + continue; if (dump_file) fprintf (dump_file, "Assume loop %i to be finite: it has an e= xit " "and -ffinite-loops is on.\n", loop->num); but that still leaves post-dominance and thus control dependence not well-defined in not backwards reachable regions and thus possibly "bogus" control-dependent DCE decisions in those. Note even with the above CD-DCE will then use control-dependence to make the loop control necessary: FOR_EACH_LOOP (loop, 0) if (!finite_loop_p (loop)) { if (dump_file) fprintf (dump_file, "cannot prove finiteness of loop %i\n", loop->num); mark_control_dependent_edges_necessary (loop->latch, false); } Which means to be absolutely sure we could use non-CD DCE whenever there are not backwards reachable blocks in the function.=