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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is that you made a former irreducible region reducible, so a new loop
appears.  I wonder why you ever want to duplicate the cond over a backedge?

One way out would be to loops_state_set (LOOPS_NEED_FIXUP) which allows
new loop discovery.

In preserves_loop_structure_p you say "requires EDGE_DFS_BACK to be current",
but the pass doesn't mark backedges.  Instead of checking EDGE_DFS_BACK
simply never duplicate loop headers.  There's also duplicating blocks
with exits which requires re-scanning loop exits (but phiopt doesn't have
recorded exits).

So I'd change preserves_loop_structure_p to just reject

  /* Never duplicate loop headers.  */
  if (e->dest->loop_father->header == e->dest)
    return false;

and do loops_state_set (LOOPS_NEED_FIXUP).  If you want to avoid altering
irreducible regions you'd have to avoid duplicating all blocks with
incoming backedges, thus mark_dfs_back_edges ().

Usually making irreducible regions reducible is good.  You can of course
end up making it even more irreducible.

Reply via email to