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

--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> ---
On Thu, 17 Sep 2026, ptomsich at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127410
> 
> --- Comment #3 from ptomsich at gcc dot gnu.org ---
> Squashing the costing before re-costing works for our use case.
> If this design (see below) is acceptable, I'd send this to the mailing list;
> if not, please let me know what other designs you'd like us to look at.
> 
> The proposed change:
> 
> diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
> index f7ff5a52214..6b9c4ee85cb 100644
> --- a/gcc/tree-vect-slp.cc
> +++ b/gcc/tree-vect-slp.cc
> @@ -10513,6 +10513,35 @@ vect_slp_undo_demotions (vec<slp_demotion> &demoted)
>    demoted.truncate (0);
>  }
> 
> +/* Reset the analysis state of the SLP tree rooted at NODE, using VISITED to
> +   avoid re-walking shared nodes.  Re-analysis has to start from a clean
> +   state, as recorded data would otherwise be merged into rather than
> +   replaced.  */
> +
> +static void
> +vect_slp_reset_analysis (slp_tree node, hash_set<slp_tree> &visited)
> +{
> +  if (!node || visited.add (node))
> +    return;
> +
> +  SLP_TREE_TYPE (node) = undef_vec_info_type;
> +  if (node->data)
> +    {
> +      delete node->data;
> +      node->data = nullptr;
> +    }
> +
> +  for (slp_tree child : SLP_TREE_CHILDREN (node))
> +    vect_slp_reset_analysis (child, visited);
> +}
> +
> +static void
> +vect_slp_reset_analysis (slp_tree node)
> +{
> +  hash_set<slp_tree> visited;
> +  vect_slp_reset_analysis (node, visited);
> +}
> +
>  /* Return true if every live lane in the SLP tree rooted at ROOT can still
>     be extracted where BB_VINFO's placement now puts its node.  Liveness
>     was decided against an earlier placement, and a demotion can move a
> @@ -10854,7 +10883,8 @@ vect_slp_region (vec<basic_block> bbs,
> vec<data_reference_p> datarefs,
>                               continue;
>                             }
>                           /* Re-analyze the modified instance and judge it
> -                            alone.  */
> +                            alone, discarding any recorded state first.  */
> +                         vect_slp_reset_analysis (SLP_INSTANCE_TREE (e));
>                           hash_set<slp_tree> avisited;
>                           auto_vec<slp_tree> avisited_vec;
>                           stmt_vector_for_cost cost_vec;

This seems to be new context, so I can't assess whether it makes sense.

It seems this would be new kind of re-analysis where you'd hit the
idempotency issue.  Resetting analysis this way would not allow
any previously analyzed alternate SLP graph entries to prevail,
so I wonder how you get away with resetting a single SLP_INSTANCE_TREE
rather than all entries of a subgraph?

Reply via email to