> Scalar IL costing receives a null vectype, causing floating-point
> statements to use the integer cost. Recover the type from the statement
> and skip vector-specific adjustments while costing scalar IL.
>
> gcc/ChangeLog:
>
> * config/riscv/riscv-vector-costs.cc (costs::add_stmt_cost): Recover
> the scalar type and skip vector adjustments for scalar costing.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/riscv/rvv/autovec/scalar-fp-cost.c: New test.
> ---
> The issue was exposed by commit fb59c5719c17 ("Avoid passing vectype != NULL
> when costing scalar IL"), which makes vectype null when costing scalar IL.
> AArch64 fixed the same issue in commit 4982644625dc by recovering the scalar
> type from the statement LHS. This patch follows the same approach for RISC-V.
>
> gcc/config/riscv/riscv-vector-costs.cc | 10 +++++++++-
> .../gcc.target/riscv/rvv/autovec/scalar-fp-cost.c | 12 ++++++++++++
> 2 files changed, 21 insertions(+), 1 deletion(-)
> create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/autovec/scalar-fp-cost.c
>
> diff --git a/gcc/config/riscv/riscv-vector-costs.cc
> b/gcc/config/riscv/riscv-vector-costs.cc
> index bfb8a0ca63..41c31dcf34 100644
> --- a/gcc/config/riscv/riscv-vector-costs.cc
> +++ b/gcc/config/riscv/riscv-vector-costs.cc
> @@ -1584,6 +1584,14 @@ costs::add_stmt_cost (int count, vect_cost_for_stmt
> kind,
> stmt_vec_info stmt_info, slp_tree node, tree vectype,
> int misalign, vect_cost_model_location where)
> {
> + /* Recover the type since VECTYPE is null when costing scalar IL. */
> + if (costing_for_scalar () && stmt_info)
I'm unsure whether or not I prefer m_cost_type == SCALAR_COST instead
here. We already use it in several other places. Granted, that was
before costing_for_scalar () existed. Very much bikeshedding, though.
The comment could explain why we need to recover vectype, though (float
vs int).
> + {
> + gcc_assert (!vectype);
> + if (tree lhs = gimple_get_lhs (STMT_VINFO_STMT (stmt_info)))
> + vectype = TREE_TYPE (lhs);
> + }
> +
> - if (vectype)
> + if (vectype && !costing_for_scalar ())
> stmt_cost = adjust_stmt_cost (kind, loop_vinfo, stmt_info, node, vectype,
> stmt_cost);
I find it confusing to set the vector type to a scalar type and then not
use it. Right now adjust_stmt_cost doesn't adjust scalar statements but
it could? If adjust_stmt_cost doesn't properly handle scalar types at
the moment, let's rather fix that.
--
Regards
Robin