]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Add gr2vr cost helper function
authorPan Li <pan2.li@intel.com>
Tue, 6 May 2025 08:42:16 +0000 (16:42 +0800)
committerPan Li <pan2.li@intel.com>
Tue, 6 May 2025 12:31:32 +0000 (20:31 +0800)
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>
gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv-vector-costs.cc
gcc/config/riscv/riscv.cc

index 2e889903eb3a598465e58127a326233ccfd05ee5..b0d5bbb8570bdbda5ea481c7bb53bdd75c147887 100644 (file)
@@ -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
 {
index 167375ca75167b69faae7475ec40241c8e5872a3..c28eecd1110e943e68f8fa9c9aa0e41392e7c613 100644 (file)
@@ -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
index a0657323f65feb07d60177e89d757560243555b8..42d501a1291befc4fd4f81603202991a93bc7c77 100644 (file)
@@ -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));
        }