]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix SLP scalar costing with stmts also used in externals
authorRichard Biener <rguenther@suse.de>
Thu, 9 Jan 2025 10:51:19 +0000 (11:51 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 15 Jan 2025 07:18:58 +0000 (08:18 +0100)
When we have the situation of an external SLP node that is
permuted the scalar stmts recorded in the permute node do not
mean the scalar computation can be removed.  We are removing
those stmts from the vectorized_scalar_stmts for this reason
but we fail to check this set when we cost scalar stmts.  Note
vectorized_scalar_stmts isn't a complete set so also pass
scalar_stmts_in_externs and check that.

The following fixes this.

This shows in PR115777 when we avoid vectorizing the load, but
on it's own doesn't help the PR yet.

PR tree-optimization/115777
* tree-vect-slp.cc (vect_bb_slp_scalar_cost): Do not
cost a scalar stmt that needs to be preserved.

gcc/tree-vect-slp.cc

index 02e7f5c4d587761e20fc14521bfdbb36e829132f..1d8e62e2fc19156b12c4139fd1b9859e42b334fd 100644 (file)
@@ -8676,6 +8676,7 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
                         slp_tree node, vec<bool, va_heap> *life,
                         stmt_vector_for_cost *cost_vec,
                         hash_set<stmt_vec_info> &vectorized_scalar_stmts,
+                        hash_set<stmt_vec_info> &scalar_stmts_in_externs,
                         hash_set<slp_tree> &visited)
 {
   unsigned i;
@@ -8690,7 +8691,12 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
       ssa_op_iter op_iter;
       def_operand_p def_p;
 
-      if (!stmt_info || (*life)[i])
+      if (!stmt_info
+         || (*life)[i]
+         /* Defs also used in external nodes are not in the
+            vectorized_scalar_stmts set as they need to be preserved.
+            Honor that.  */
+         || scalar_stmts_in_externs.contains (stmt_info))
        continue;
 
       stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info);
@@ -8809,7 +8815,8 @@ next_lane:
              subtree_life.safe_splice (*life);
            }
          vect_bb_slp_scalar_cost (vinfo, child, &subtree_life, cost_vec,
-                                  vectorized_scalar_stmts, visited);
+                                  vectorized_scalar_stmts,
+                                  scalar_stmts_in_externs, visited);
          subtree_life.truncate (0);
        }
     }
@@ -8891,7 +8898,7 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
       vect_bb_slp_scalar_cost (bb_vinfo,
                               SLP_INSTANCE_TREE (instance),
                               &life, &scalar_costs, vectorized_scalar_stmts,
-                              visited);
+                              scalar_stmts_in_externs, visited);
       vector_costs.safe_splice (instance->cost_vec);
       instance->cost_vec.release ();
     }