diff options
author | Richard Biener <rguenther@suse.de> | 2023-06-26 12:51:37 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-06-26 14:14:54 +0200 |
commit | 53d6f57c1b20c6da52aefce737fb7d5263686ba3 (patch) | |
tree | ea464de31dd3bd20324ceb81ea7dd6aa7aa9881d /gcc/tree-vect-slp.cc | |
parent | a024176a97b0176f526862836c33e283b8db4197 (diff) | |
download | gcc-53d6f57c1b20c6da52aefce737fb7d5263686ba3.zip gcc-53d6f57c1b20c6da52aefce737fb7d5263686ba3.tar.gz gcc-53d6f57c1b20c6da52aefce737fb7d5263686ba3.tar.bz2 |
tree-optimization/110381 - preserve SLP permutation with in-order reductions
The following fixes a bug that manifests itself during fold-left
reduction transform in picking not the last scalar def to replace
and thus double-counting some elements. But the underlying issue
is that we merge a load permutation into the in-order reduction
which is of course wrong.
Now, reduction analysis has not yet been performend when optimizing
permutations so we have to resort to check that ourselves.
PR tree-optimization/110381
* tree-vect-slp.cc (vect_optimize_slp_pass::start_choosing_layouts):
Materialize permutes before fold-left reductions.
* gcc.dg/vect/pr110381.c: New testcase.
Diffstat (limited to 'gcc/tree-vect-slp.cc')
-rw-r--r-- | gcc/tree-vect-slp.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index ab89a82..fee992d 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -4673,14 +4673,28 @@ vect_optimize_slp_pass::start_choosing_layouts () m_partition_layout_costs.safe_grow_cleared (m_partitions.length () * m_perms.length ()); - /* We have to mark outgoing permutations facing non-reduction graph - entries that are not represented as to be materialized. */ + /* We have to mark outgoing permutations facing non-associating-reduction + graph entries that are not represented as to be materialized. + slp_inst_kind_bb_reduc currently only covers associatable reductions. */ for (slp_instance instance : m_vinfo->slp_instances) if (SLP_INSTANCE_KIND (instance) == slp_inst_kind_ctor) { unsigned int node_i = SLP_INSTANCE_TREE (instance)->vertex; m_partitions[m_vertices[node_i].partition].layout = 0; } + else if (SLP_INSTANCE_KIND (instance) == slp_inst_kind_reduc_chain) + { + stmt_vec_info stmt_info + = SLP_TREE_REPRESENTATIVE (SLP_INSTANCE_TREE (instance)); + stmt_vec_info reduc_info = info_for_reduction (m_vinfo, stmt_info); + if (needs_fold_left_reduction_p (TREE_TYPE + (gimple_get_lhs (stmt_info->stmt)), + STMT_VINFO_REDUC_CODE (reduc_info))) + { + unsigned int node_i = SLP_INSTANCE_TREE (instance)->vertex; + m_partitions[m_vertices[node_i].partition].layout = 0; + } + } /* Check which layouts each node and partition can handle. Calculate the weights associated with inserting layout changes on edges. */ |