> -  /* Cost of a permute operation.  */
> -  const int permute_cost;
> +  /* Cost of a permute operation for LMUL 1, 2, 4, 8.  */
> +  const int permute_cost[4];
>  
>    /* Cost of an aligned vector load.  */
>    const int align_load_cost;
> diff --git a/gcc/config/riscv/riscv-vector-costs.cc 
> b/gcc/config/riscv/riscv-vector-costs.cc
> index 924a0330103..9eeeaff05c0 100644
> --- a/gcc/config/riscv/riscv-vector-costs.cc
> +++ b/gcc/config/riscv/riscv-vector-costs.cc
> @@ -1523,8 +1523,10 @@ costs::adjust_stmt_cost (enum vect_cost_for_stmt kind, 
> loop_vec_info loop,
>  
>    /* Apply LMUL cost scaling uniformly to all vector operations.
>       Larger LMUL values have higher latency and register pressure,
> -     which affects performance regardless of loop structure.  */
> -  if (VECTOR_TYPE_P (vectype))
> +     which affects performance regardless of loop structure.
> +     Permutes have already looked up their per-LMUL cost table in
> +     builtin_vectorization_cost.  */
> +  if (VECTOR_TYPE_P (vectype) && kind != vec_perm)
>      {
>        unsigned lmul_factor = get_lmul_cost_scaling (TYPE_MODE (vectype));

I would prefer to extend get_lmul_cost_scaling and add a 'kind' param.

Then maybe
 if (kind != vec_perm)
   existing code (linear scaling);
 else
   lookup perm scaling;

and...

>      case vec_perm:
> -      return common_costs->permute_cost;
> +      return is_frac_vlmul_p (TYPE_MODE (vectype))
> +     ? common_costs->permute_cost[LMUL_1]
> +     : common_costs->permute_cost[get_vlmul (TYPE_MODE (vectype))];

... here maybe just always use permute_cost[LMUL1]?

-- 
Regards
 Robin

Reply via email to