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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 8f9f76e258c..76ff2cfea2f 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -1717,6 +1717,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, @@ -1999,6 +2000,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)) -- 2.43.0