aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPan Li <pan2.li@intel.com>2025-05-06 16:42:16 +0800
committerPan Li <pan2.li@intel.com>2025-05-06 20:31:32 +0800
commit9e9eb78bf4b77a049be00fb9ab0047170f19c9ea (patch)
tree37e420624a70289d5788d9f344a23e81fbb99522
parent17c1602d5e7b237357b94808399a68ab77d42640 (diff)
downloadgcc-9e9eb78bf4b77a049be00fb9ab0047170f19c9ea.zip
gcc-9e9eb78bf4b77a049be00fb9ab0047170f19c9ea.tar.gz
gcc-9e9eb78bf4b77a049be00fb9ab0047170f19c9ea.tar.bz2
RISC-V: Add gr2vr cost helper function
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.li@intel.com>
-rw-r--r--gcc/config/riscv/riscv-protos.h1
-rw-r--r--gcc/config/riscv/riscv-vector-costs.cc2
-rw-r--r--gcc/config/riscv/riscv.cc19
3 files changed, 19 insertions, 3 deletions
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 2e88990..b0d5bbb 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 167375c..c28eecd 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 a065732..42d501a 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,21 @@ 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 +12621,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));
}