On Mon, Sep 7, 2026 at 4:35 PM Konstantinos Eleftheriou <[email protected]> wrote: > > Convert the pre-existing unroll-and-jam path to use the > compute_jam_dependence_factors helper introduced for the reduction-jam > path; both paths now share one data-dep + adjust_unroll_factor walk > with a single set of correctness checks. > > No functional change.
This might have been better 1/2, splitting out this helper? Richard. > gcc/ChangeLog: > > * gimple-loop-jam.cc (tree_loop_unroll_and_jam): Replace the > inline data-dep + adjust_unroll_factor walk with a call to > compute_jam_dependence_factors. > > Signed-off-by: Konstantinos Eleftheriou <[email protected]> > --- > > gcc/gimple-loop-jam.cc | 100 ++++++----------------------------------- > 1 file changed, 13 insertions(+), 87 deletions(-) > > diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc > index 527f7c6cce35..493e4a0a3a0d 100644 > --- a/gcc/gimple-loop-jam.cc > +++ b/gcc/gimple-loop-jam.cc > @@ -1442,97 +1442,27 @@ tree_loop_unroll_and_jam (void) > continue; > } > > - vec<data_reference_p> datarefs = vNULL; > - vec<ddr_p> dependences = vNULL; > - unsigned unroll_factor, profit_unroll, removed; > - class tree_niter_desc desc; > - bool unroll = false; > - > - auto_vec<loop_p, 3> loop_nest; > - if (!compute_data_dependences_for_loop (outer, true, &loop_nest, > - &datarefs, &dependences)) > - { > - if (dump_file && (dump_flags & TDF_DETAILS)) > - fprintf (dump_file, "Cannot analyze data dependencies\n"); > - free_data_refs (datarefs); > - free_dependence_relations (dependences); > - continue; > - } > - if (!datarefs.length ()) > + unsigned unroll_factor, profit_unroll, removed, num_datarefs; > + if (!compute_jam_dependence_factors (outer, loop, &unroll_factor, > + &profit_unroll, &removed, > + &num_datarefs) > + || num_datarefs == 0) > continue; > > - if (dump_file && (dump_flags & TDF_DETAILS)) > - dump_data_dependence_relations (dump_file, dependences); > - > - unroll_factor = (unsigned)-1; > - profit_unroll = 1; > - removed = 0; > - > - /* Check all dependencies. */ > - unsigned i; > - struct data_dependence_relation *ddr; > - FOR_EACH_VEC_ELT (dependences, i, ddr) > - { > - struct data_reference *dra, *drb; > - > - /* If the refs are independent there's nothing to do. */ > - if (DDR_ARE_DEPENDENT (ddr) == chrec_known) > - continue; > - > - dra = DDR_A (ddr); > - drb = DDR_B (ddr); > - > - /* Nothing interesting for the self dependencies, except for WAW if > - the access function is not affine or constant because we may end > - up reordering writes to the same location. */ > - if (dra == drb) > - { > - if (DR_IS_WRITE (dra) > - && !DR_ACCESS_FNS (dra).is_empty () > - && DDR_ARE_DEPENDENT (ddr) == chrec_dont_know) > - { > - unroll_factor = 0; > - break; > - } > - else > - continue; > - } > - > - /* Now check the distance vector, for determining a sensible > - outer unroll factor, and for validity of merging the inner > - loop copies. */ > - if (!adjust_unroll_factor (loop, ddr, &unroll_factor, > &profit_unroll, > - &removed)) > - { > - /* Couldn't get the distance vector. For two reads that's > - harmless (we assume we should unroll). For at least > - one write this means we can't check the dependence direction > - and hence can't determine safety. */ > - > - if (DR_IS_WRITE (dra) || DR_IS_WRITE (drb)) > - { > - unroll_factor = 0; > - break; > - } > - } > - } > - > - /* We regard a user-specified minimum percentage of zero as a request > - to ignore all profitability concerns and apply the transformation > - always. */ > + /* min-percent of zero requests "ignore profitability". */ > if (!param_unroll_jam_min_percent) > - profit_unroll = MAX(2, profit_unroll); > - else if (removed * 100 / datarefs.length () > - < (unsigned)param_unroll_jam_min_percent) > + profit_unroll = MAX (2, profit_unroll); > + else if (removed * 100 / num_datarefs > + < (unsigned) param_unroll_jam_min_percent) > profit_unroll = 1; > if (unroll_factor > profit_unroll) > unroll_factor = profit_unroll; > - if (unroll_factor > (unsigned)param_unroll_jam_max_unroll) > + if (unroll_factor > (unsigned) param_unroll_jam_max_unroll) > unroll_factor = param_unroll_jam_max_unroll; > - unroll = (unroll_factor > 1 > - && can_unroll_loop_p (outer, unroll_factor, &desc)); > > - if (unroll) > + class tree_niter_desc desc; > + if (unroll_factor > 1 > + && can_unroll_loop_p (outer, unroll_factor, &desc)) > { > if (dump_enabled_p ()) > dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | TDF_DETAILS, > @@ -1549,10 +1479,6 @@ tree_loop_unroll_and_jam (void) > bitmap_set_bit (exit_bbs, single_exit (outer)->dest->index); > todo |= do_rpo_vn (cfun, loop_preheader_edge (outer), exit_bbs); > } > - > - loop_nest.release (); > - free_dependence_relations (dependences); > - free_data_refs (datarefs); > } > > if (todo) > -- > 2.55.0 >
