]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Introduce vr2gpr-cost= for customizing the cost when vr2gpr
authorPan Li <pan2.li@intel.com>
Wed, 4 Feb 2026 02:13:38 +0000 (10:13 +0800)
committerPan Li <pan2.li@intel.com>
Thu, 5 Feb 2026 01:23:25 +0000 (09:23 +0800)
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 <pan2.li@intel.com>
gcc/config/riscv/riscv-opts.h
gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv-vector-costs.cc
gcc/config/riscv/riscv.cc
gcc/config/riscv/riscv.opt

index 2b6553ff87d29997bcf969ec531db6cf03d9701e..ab67d231d430abff313b9d28bab2a07de9786296 100644 (file)
@@ -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
index 7af463a43b9dd94c9dc515cc11425a4a6b5c6227..2c163ddc3249d75d806b90f8435ac5cabde6d49d 100644 (file)
@@ -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
index 782796ed43e12defa23223c37f1767d505d049aa..b9012a52893ded5bbf1e0eb149b7b3c752f4565a 100644 (file)
@@ -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:
index 472c7e5f4920c2ab0ebd99eff69b7439d65d1004..1bb8f98ddb5100978aad2880afa3d8f8862350c9 100644 (file)
@@ -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.  */
index 70f2fb0f5d52f4b31f182186984b9b2cfbef1e5c..4a2d8ed24080171c9b6b30d81840c84378df6c55 100644 (file)
@@ -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.