[Bug tree-optimization/99101] optimization bug with -ffinite-loops

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Mar 3 14:37:50 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99101

--- Comment #23 from Richard Biener <rguenth at gcc dot gnu.org> ---
Just for the record we had the idea to apply the "bolt" of marking the latch
control dependence (as done for possibly infinite loops) for loops containing
stmts with side-effects.

diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index c027230acdc..c07b60bf25c 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -695,6 +695,12 @@ propagate_necessity (bool aggressive)
          if (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)
              && !bitmap_bit_p (visited_control_parents, bb->index))
            mark_control_dependent_edges_necessary (bb, false);
+         /* If the stmt has side-effects the number of invocations matter.
+            In this case mark the containing loop control.  */
+         if (gimple_has_side_effects (stmt)
+             && bb->loop_father->num != 0)
+           mark_control_dependent_edges_necessary (bb->loop_father->latch,
+                                                   false);
        }

       if (gimple_code (stmt) == GIMPLE_PHI

But while that works for CDDCE1, CDDCE2 is presented a slightly altered CFG
that somehow prevents it from working.  Which also means that both loops
need to be considered infinite for the present bolting to work.


More information about the Gcc-bugs mailing list