Linear LMUL scaling is not enough for vec_perm like vrgather, which
usually scale quadratically with LMUL. We can't tell whether a permute
op is a cheaper one (like vslides) here, so this patch just scale all
vec_perm quadratically for now.
Regtested on rv64gcv, showed regressions in 4 files:
- gcc.target/riscv/rvv/autovec/partial/slp-{1,3,5}.c: Prefers vlseg8
because generic segment cost is too cheap (1).
- gcc.target/riscv/rvv/autovec/vls/bswap16-0.c: bswap16 is costed as
vec_perm, so quadratic scaling avoids large LMUL.
I leave testcases untouched for now. My thought is:
- For slp-{1,3,5}.c, we need a segment cost change (cost table
update like C950 or introduce segment scaling) in a follow-up patch.
- For bswap16-0.c, no idea how to address it since we can't recognize
it's a cheaper perm. Maybe just leave it as is? I think keeping
permutes at a lower LMUL won't be a bad thing.
gcc/ChangeLog:
* config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost): Scale
vec_perm quadratically by LMUL factor.
Signed-off-by: Zhongyao Chen <[email protected]>
---
gcc/config/riscv/riscv-vector-costs.cc | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/gcc/config/riscv/riscv-vector-costs.cc
b/gcc/config/riscv/riscv-vector-costs.cc
index 924a0330103..7f0e13b6e10 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -1528,7 +1528,13 @@ costs::adjust_stmt_cost (enum vect_cost_for_stmt kind,
loop_vec_info loop,
{
unsigned lmul_factor = get_lmul_cost_scaling (TYPE_MODE (vectype));
if (lmul_factor > 1)
- stmt_cost *= lmul_factor;
+ {
+ /* vec_perm like vrgather usually scale quadratically with LMUL. */
+ if (kind == vec_perm)
+ stmt_cost *= lmul_factor * lmul_factor;
+ else
+ stmt_cost *= lmul_factor;
+ }
}
return stmt_cost;
--
2.43.0