From: Pan Li Date: Wed, 4 Feb 2026 02:13:38 +0000 (+0800) Subject: RISC-V: Introduce vr2gpr-cost= for customizing the cost when vr2gpr X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=166da15d1fec719949ac7f1343819d505bf5a24e;p=thirdparty%2Fgcc.git RISC-V: Introduce vr2gpr-cost= for customizing the cost when vr2gpr The middle-end pass NULL_TREE in previous, and then skip the adjust_stmt_cost step which has count the cost of vr2gpr. After Richard introduced more like slp_node with its vectype for recording the cost, the adjust_stmt_cost will be hit and plus the cost of vr2gpr now. And then fail to vectorize due to cost value of vr2gpr is counted. This PATCH would like to introduce another param named vr2gpr-cost, to allow the cmdline provide the cost value of vr2gpr. Then we can leverage the this param to make the failed test happy. For further enhancement of the cost value customization, we would like to defer to next stage-1, aka GCC-17. PR/target 123916 gcc/ChangeLog: * config/riscv/riscv-opts.h (GPR2VR_COST_UNPROVIDED): Depend on default unprovided value. (FPR2VR_COST_UNPROVIDED): Ditto. (VR2GPR_COST_UNPROVIDED): Ditto. (COST_UNPROVIDED): Add new default unprovided value. * config/riscv/riscv-protos.h (get_vr2gr_cost): Add new func decl. * config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost): Leverage new func to get cost of vr2gpr. * config/riscv/riscv.cc (riscv_register_move_cost): Ditto. (get_vr2gr_cost): Add new func to wrap access to the cost of the vr2gpr. * config/riscv/riscv.opt: Add new param vr2gpr-cost. Signed-off-by: Pan Li --- diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index 2b6553ff87d..ab67d231d43 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -172,8 +172,10 @@ enum riscv_tls_type { #define TARGET_VECTOR_AUTOVEC_SEGMENT \ (TARGET_VECTOR && riscv_mautovec_segment) -#define GPR2VR_COST_UNPROVIDED -1 -#define FPR2VR_COST_UNPROVIDED -1 +#define COST_UNPROVIDED -1 +#define GPR2VR_COST_UNPROVIDED COST_UNPROVIDED +#define VR2GPR_COST_UNPROVIDED COST_UNPROVIDED +#define FPR2VR_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 7af463a43b9..2c163ddc324 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -878,6 +878,7 @@ const struct riscv_tune_info * riscv_parse_tune (const char *, bool); const cpu_vector_cost *get_vector_costs (); int get_gr2vr_cost (); +int get_vr2gr_cost (); int get_fr2vr_cost (); enum diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index 782796ed43e..b9012a52893 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -1254,7 +1254,7 @@ costs::adjust_stmt_cost (enum vect_cost_for_stmt kind, loop_vec_info loop, break; case vec_to_scalar: stmt_cost += (FLOAT_TYPE_P (vectype) ? costs->regmove->VR2FR - : costs->regmove->VR2GR); + : 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 472c7e5f492..1bb8f98ddb5 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -10728,7 +10728,7 @@ riscv_register_move_cost (machine_mode mode, if (from == V_REGS) { if (to_is_gpr) - return get_vector_costs ()->regmove->VR2GR; + return get_vr2gr_cost (); else if (to_is_fpr) return get_vector_costs ()->regmove->VR2FR; } @@ -14213,6 +14213,21 @@ get_gr2vr_cost () return cost; } +/* Return the cost of operation that move from vr to gpr. + It will take the value of --param=vr2gpr_cost if it is provided. + Or the default regmove->VR2GR will be returned. */ + +int +get_vr2gr_cost () +{ + int cost = get_vector_costs ()->regmove->VR2GR; + + if (vr2gpr_cost != VR2GPR_COST_UNPROVIDED) + cost = vr2gpr_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. */ diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 70f2fb0f5d5..4a2d8ed2408 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -286,6 +286,10 @@ Max number of bytes to compare as part of inlined strcmp/strncmp routines (defau Target RejectNegative Joined UInteger Var(gpr2vr_cost) Init(GPR2VR_COST_UNPROVIDED) Set the cost value of the rvv instruction when operate from GPR to VR. +-param=vr2gpr-cost= +Target RejectNegative Joined UInteger Var(vr2gpr_cost) Init(VR2GPR_COST_UNPROVIDED) +Set the cost value of the rvv instruction when operate from VR to GPR . + -param=fpr2vr-cost= 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.