From: Pan Li <pan2...@intel.com> After we introduced the --param=gpr2vr-cost option to set the cost value of when operation act from gpr to vr, we would like to introduce a new helper function to get the cost of gp2vr. And then make sure all reference to gr2vr should go this helper function.
The helper function will pick up the GR2VR value if the above option is not provided, or the default GR2VR will be returned. gcc/ChangeLog: * config/riscv/riscv-protos.h (get_gr2vr_cost): Add new decl to get the cost of gr2vr. * config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost): Leverage the helper function to get the cost of gr2vr. * config/riscv/riscv.cc (riscv_register_move_cost): Ditto. (riscv_builtin_vectorization_cost): Ditto. (get_gr2vr_cost): Add new impl of the helper function. Signed-off-by: Pan Li <pan2...@intel.com> --- gcc/config/riscv/riscv-protos.h | 1 + gcc/config/riscv/riscv-vector-costs.cc | 2 +- gcc/config/riscv/riscv.cc | 22 ++++++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 2e889903eb3..b0d5bbb8570 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -836,6 +836,7 @@ struct riscv_tune_info { const struct riscv_tune_info * riscv_parse_tune (const char *, bool); const cpu_vector_cost *get_vector_costs (); +int get_gr2vr_cost (); enum { diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index 167375ca751..c28eecd1110 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -1121,7 +1121,7 @@ costs::adjust_stmt_cost (enum vect_cost_for_stmt kind, loop_vec_info loop, { case scalar_to_vec: stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->FR2VR - : costs->regmove->GR2VR); + : get_gr2vr_cost ()); break; case vec_to_scalar: stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->VR2FR diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index a0657323f65..efe0ce0dd72 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -9690,7 +9690,7 @@ riscv_register_move_cost (machine_mode mode, if (to == V_REGS) { if (from_is_gpr) - return get_vector_costs ()->regmove->GR2VR; + return get_gr2vr_cost (); else if (from_is_fpr) return get_vector_costs ()->regmove->FR2VR; } @@ -12540,6 +12540,24 @@ get_vector_costs () return costs; } +/* + * Return the cost of operation that move from gpr to vr. + * + * It will take the value of --param=gpr2vr_cost if it is provided. + * Or the default regmove->GR2VR will be returned. + */ + +int +get_gr2vr_cost () +{ + int cost = get_vector_costs ()->regmove->GR2VR; + + if (gpr2vr_cost != GPR2VR_COST_UNPROVIDED) + cost = gpr2vr_cost; + + return cost; +} + /* Implement targetm.vectorize.builtin_vectorization_cost. */ static int @@ -12606,7 +12624,7 @@ riscv_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost, { /* TODO: This is too pessimistic in case we can splat. */ int regmove_cost = fp ? costs->regmove->FR2VR - : costs->regmove->GR2VR; + : get_gr2vr_cost (); return (regmove_cost + common_costs->scalar_to_vec_cost) * estimated_poly_value (TYPE_VECTOR_SUBPARTS (vectype)); } -- 2.43.0