]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid passing vectype != NULL when costing scalar IL
authorRichard Biener <rguenther@suse.de>
Tue, 29 Jul 2025 07:20:42 +0000 (09:20 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 31 Jul 2025 06:31:17 +0000 (08:31 +0200)
The following makes sure to not leak a set vectype on a stmt when
doing scalar IL costing as this can confuse vector cost models
which do not look at m_costing_for_scalar most of the time.

* tree-vectorizer.h (vector_costs::costing_for_scalar): New
accessor.
(add_stmt_cost): For scalar costing force vectype to NULL.
Verify we do not pass in a SLP node.

gcc/tree-vectorizer.h

index e190027943240ac7b04a2a1816fc2f490e7e7ef1..222a723485cb84572d5a1c31680580a524c1cf8a 100644 (file)
@@ -1718,6 +1718,7 @@ public:
   unsigned int total_cost () const;
   unsigned int suggested_unroll_factor () const;
   machine_mode suggested_epilogue_mode (int &masked) const;
+  bool costing_for_scalar () const { return m_costing_for_scalar; }
 
 protected:
   unsigned int record_stmt_cost (stmt_vec_info, vect_cost_model_location,
@@ -2000,6 +2001,13 @@ add_stmt_cost (vector_costs *costs, int count,
               tree vectype, int misalign,
               enum vect_cost_model_location where)
 {
+  /* Even though a vector type might be set on stmt do not pass that on when
+     costing the scalar IL.  A SLP node shouldn't have been recorded.  */
+  if (costs->costing_for_scalar ())
+    {
+      vectype = NULL_TREE;
+      gcc_checking_assert (node == NULL);
+    }
   unsigned cost = costs->add_stmt_cost (count, kind, stmt_info, node, vectype,
                                        misalign, where);
   if (dump_file && (dump_flags & TDF_DETAILS))