]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Introduce vr2fpr-cost= for customizing the cost when vr2fpr
authorPan Li <pan2.li@intel.com>
Wed, 4 Feb 2026 04:55:28 +0000 (12:55 +0800)
committerPan Li <pan2.li@intel.com>
Thu, 5 Feb 2026 01:23:25 +0000 (09:23 +0800)
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 <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 ab67d231d430abff313b9d28bab2a07de9786296..1c44bc4e6eceab509dfd961c8415fbb4c19b3e0f 100644 (file)
@@ -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
index 2c163ddc3249d75d806b90f8435ac5cabde6d49d..0734c31ec5628ae12a0f0e44b7074e86a86fbf8f 100644 (file)
@@ -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
 {
index b9012a52893ded5bbf1e0eb149b7b3c752f4565a..f582551eba79ea9e066da16bbbfcaa58459a66f3 100644 (file)
@@ -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:
index 1bb8f98ddb5100978aad2880afa3d8f8862350c9..8b22556b546c40425f6a09b14ebe692f71551451 100644 (file)
@@ -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
index 4a2d8ed24080171c9b6b30d81840c84378df6c55..2c26ee99691315d1374d6e5d4ddebf30f259eb1f 100644 (file)
@@ -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.