https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96487
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2020-08-06 Ever confirmed|0 |1 CC| |hubicka at gcc dot gnu.org, | |rguenth at gcc dot gnu.org Status|UNCONFIRMED |NEW Keywords| |missed-optimization --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- I think the issue is that control dependence looks different - for C the latch is control dependent on itself while for C++ it ends up being control dependent on the outgoing edges from the conditional that ends up being marked necessary. I guess both answers are somewhat "wrong" but it boils down to the testcase not having any edges to exit and thus post-dominance being somewhat ill-defined. Doing connect_infinite_loops_to_exit () doesn't help because that as well makes different decisions based on the BB order. So the question is whether DCE should do sth different than marking control dependent edges of each non-finites loop latch, especially in the case where the loop has no exit (if there are exits we should get to the "first" exit test - that's the whole idea here). That is, if there's no exit maybe simply mark the latch as bb_contains_live_stmts? diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index fae5ae72340..a66fc34c9e5 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -450,7 +450,10 @@ find_obviously_necessary_stmts (bool aggressive) { if (dump_file) fprintf (dump_file, "cannot prove finiteness of loop %i\n", loop->num); - mark_control_dependent_edges_necessary (loop->latch, false); + if (loop->exits->next->e) + mark_control_dependent_edges_necessary (loop->latch, false); + else + bitmap_set_bit (bb_contains_live_stmts, loop->latch->index); } } }