> > /* 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]?
I actually had a version like this:
/* In riscv_builtin_vectorization_cost: */
case vec_perm:
return common_costs->permute_cost[LMUL_1];
/* In adjust_stmt_cost: */
if (VECTOR_TYPE_P (vectype))
{
if (kind == vec_perm)
stmt_cost = common_costs->permute_cost[vlmul];
else
stmt_cost *= get_lmul_cost_scaling (TYPE_MODE (vectype));
}
I ended up changing it to the current version because the cost table
already gives the full per-LMUL costs, so return permute_cost[LMUL_1] in
builtin_vectorization_cost, but in adjust_stmt_cost, we dont use it,
and yet lookup permute_cost again and overwrite the stmt_cost. that
felt a bit weird.
On the other hand, this way put the LMUL scaling adjust in one place,
so both ok to me. your call.
--
Regards,
Zhongyao