https://gcc.gnu.org/g:25d819a6e4dd32b786120a3f4d0f23eed15762f7
commit r16-7296-g25d819a6e4dd32b786120a3f4d0f23eed15762f7 Author: Pan Li <[email protected]> Date: Wed Feb 4 12:55:28 2026 +0800 RISC-V: Introduce vr2fpr-cost= for customizing the cost when vr2fpr Similar to vr2gpr-cost=, add the one for fpr as well. PR/target 123916 gcc/ChangeLog: * config/riscv/riscv-opts.h (VR2FPR_COST_UNPROVIDED): Add new sentinel for unprovided cost. * config/riscv/riscv-protos.h (get_vr2fr_cost): Add new func decl. * config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost): Leverage new func to get cost of vr2fpr. * config/riscv/riscv.cc (riscv_register_move_cost): Ditto. (get_vr2fr_cost): Add new func to wrap access to the cost of the vr2fpr. * config/riscv/riscv.opt: Add new param vr2fpr-cost. Signed-off-by: Pan Li <[email protected]> Diff: --- gcc/config/riscv/riscv-opts.h | 1 + gcc/config/riscv/riscv-protos.h | 1 + gcc/config/riscv/riscv-vector-costs.cc | 4 ++-- gcc/config/riscv/riscv.cc | 17 ++++++++++++++++- gcc/config/riscv/riscv.opt | 4 ++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index ab67d231d430..1c44bc4e6ece 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -176,6 +176,7 @@ enum riscv_tls_type { #define GPR2VR_COST_UNPROVIDED COST_UNPROVIDED #define VR2GPR_COST_UNPROVIDED COST_UNPROVIDED #define FPR2VR_COST_UNPROVIDED COST_UNPROVIDED +#define VR2FPR_COST_UNPROVIDED COST_UNPROVIDED /* Extra extension flags, used for carry extra info for a RISC-V extension. */ enum diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 2c163ddc3249..0734c31ec562 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -880,6 +880,7 @@ const cpu_vector_cost *get_vector_costs (); int get_gr2vr_cost (); int get_vr2gr_cost (); int get_fr2vr_cost (); +int get_vr2fr_cost (); enum { diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index b9012a52893d..f582551eba79 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -1253,8 +1253,8 @@ costs::adjust_stmt_cost (enum vect_cost_for_stmt kind, loop_vec_info loop, += (FLOAT_TYPE_P (vectype) ? get_fr2vr_cost () : get_gr2vr_cost ()); break; case vec_to_scalar: - stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->VR2FR - : get_vr2gr_cost ()); + stmt_cost + += (FLOAT_TYPE_P (vectype) ? get_vr2fr_cost () : get_vr2gr_cost ()); break; case vector_load: case vector_store: diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 1bb8f98ddb51..8b22556b546c 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -10730,7 +10730,7 @@ riscv_register_move_cost (machine_mode mode, if (to_is_gpr) return get_vr2gr_cost (); else if (to_is_fpr) - return get_vector_costs ()->regmove->VR2FR; + return get_vr2fr_cost (); } if (to == V_REGS) @@ -14243,6 +14243,21 @@ get_fr2vr_cost () return cost; } +/* Return the cost of moving data from floating-point to vector register. + It will take the value of --param=fpr2vr-cost if it is provided. + Otherwise the default regmove->FR2VR will be returned. */ + +int +get_vr2fr_cost () +{ + int cost = get_vector_costs ()->regmove->VR2FR; + + if (vr2fpr_cost != VR2FPR_COST_UNPROVIDED) + cost = vr2fpr_cost; + + return cost; +} + /* Implement targetm.vectorize.builtin_vectorization_cost. */ static int diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 4a2d8ed24080..2c26ee996913 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -294,6 +294,10 @@ Set the cost value of the rvv instruction when operate from VR to GPR . Target RejectNegative Joined UInteger Var(fpr2vr_cost) Init(FPR2VR_COST_UNPROVIDED) Set the cost value of the rvv instruction when operate from FPR to VR. +-param=vr2fpr-cost= +Target RejectNegative Joined UInteger Var(vr2fpr_cost) Init(VR2FPR_COST_UNPROVIDED) +Set the cost value of the rvv instruction when operate from VR to FPR. + -param=riscv-autovec-mode= Target Undocumented RejectNegative Joined Var(riscv_autovec_mode) Save Set the only autovec mode to try.
