https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77283
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- Patch to fix the testcase, but will eventually regress the path-splitting testcase again. The IV increment may be combined with a stmt in the path thus more analysis would be required here. I guess if there are no non-virtual PHIs in the joiner in addition to <= 2 stmts then we can be reasonably sure of no CSE possibilities. Index: gcc/gimple-ssa-split-paths.c =================================================================== --- gcc/gimple-ssa-split-paths.c (revision 239560) +++ gcc/gimple-ssa-split-paths.c (working copy) @@ -200,6 +200,12 @@ is_feasible_trace (basic_block bb) } } + /* If the join block has only the conditional and possibly an IV + increment there are no possible CSE/DCE opportunities to expose by + duplicating it. */ + if (num_stmts_in_join <= 2) + return false; + /* We may want something here which looks at dataflow and tries to guess if duplication of BB is likely to result in simplification of instructions in BB in either the original or the duplicate. */ Or simply look at all PHIs (no PHIs == no CSE/DCE possibility anyway) and see if any of its result has a use in the joiner. If not -> fail. Index: gcc/gimple-ssa-split-paths.c =================================================================== --- gcc/gimple-ssa-split-paths.c (revision 239560) +++ gcc/gimple-ssa-split-paths.c (working copy) @@ -32,6 +32,9 @@ along with GCC; see the file COPYING3. #include "tracer.h" #include "predict.h" #include "params.h" +#include "gimple-ssa.h" +#include "tree-phinodes.h" +#include "ssa-iterators.h" /* Given LATCH, the latch block in a loop, see if the shape of the path reaching LATCH is suitable for being split by duplication. @@ -200,6 +203,34 @@ is_feasible_trace (basic_block bb) } } + /* If the joiner has no PHIs with uses inside it there is zero chance + of CSE/DCE possibilities exposed by duplicating it. */ + bool found_phi_with_uses_in_bb = false; + for (gphi_iterator si = gsi_start_phis (bb); ! gsi_end_p (si); + gsi_next (&si)) + { + gphi *phi = si.phi (); + use_operand_p use_p; + imm_use_iterator iter; + FOR_EACH_IMM_USE_FAST (use_p, iter, gimple_phi_result (phi)) + if (gimple_bb (USE_STMT (use_p)) == bb) + { + found_phi_with_uses_in_bb = true; + break; + } + if (found_phi_with_uses_in_bb) + break; + } + if (! found_phi_with_uses_in_bb) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Block %d is a join that does not expose CSE/DCE " + "opportunities when duplicated.\n", + bb->index); + return false; + } + /* We may want something here which looks at dataflow and tries to guess if duplication of BB is likely to result in simplification of instructions in BB in either the original or the duplicate. */ This one FAILs gcc.dg/tree-ssa/split-path-7.c though. But it looks quite artificial (with empty if blocks, etc.). Looking at the IL definitely only one path is profitable to split. Jeff?