Follow-up for commit fa20d1603db to update generic segment permute costs,
as the original cost was too cheap (1). Update them to Ascalon's benchmark
numbers from:
https://camel-cdr.github.io/rvv-bench-results/tt_asc_x/index.html
The published values ({1, 2.5, 4, 9, 9.6, 10.6, 11}) are rounded up to
integers ({1, 3, 4, 9, 10, 11, 11}).
Also fix segment store costing: store-lanes counts each vector in the group
(count = ncopies * group_size), scaling the segment permute cost by
group_size. Since the segment permute cost is per instruction, it should
not be multiplied by group_size. Normalize count to the number of segment
store instructions with CEIL (count, group_size) in costs::add_stmt_cost.
Testsuite changes:
- partial/slp-{1,3,5}.c: Remove .VEC_PERM xfails as higher segment costs
now favor SLP over LOAD/STORE_LANES.
- zve64d-1.c & zve64f-1.c: foo4 in template-1.h is now successfully
vectorized, so update expectation.
Regtested on rv64gcv.
gcc/ChangeLog:
* config/riscv/riscv-vector-costs.cc (costs::add_stmt_cost): Normalize
count for store-lanes.
* config/riscv/riscv.cc (rvv_vls_vector_cost): Update
segment_permute_{2-8}.
(rvv_vla_vector_cost): Likewise.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/partial/slp-1.c: Remove xfail on
.VEC_PERM.
* gcc.target/riscv/rvv/autovec/partial/slp-3.c: Likewise.
* gcc.target/riscv/rvv/autovec/partial/slp-5.c: Likewise.
* gcc.target/riscv/rvv/autovec/zve64d-1.c: Adjust expectation.
* gcc.target/riscv/rvv/autovec/zve64f-1.c: Likewise.
Signed-off-by: Zhongyao Chen <[email protected]>
---
gcc/config/riscv/riscv-vector-costs.cc | 10 ++++++++
gcc/config/riscv/riscv.cc | 24 +++++++++----------
.../riscv/rvv/autovec/partial/slp-1.c | 2 +-
.../riscv/rvv/autovec/partial/slp-3.c | 4 +---
.../riscv/rvv/autovec/partial/slp-5.c | 4 +---
.../gcc.target/riscv/rvv/autovec/zve64d-1.c | 5 +---
.../gcc.target/riscv/rvv/autovec/zve64f-1.c | 5 +---
7 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/gcc/config/riscv/riscv-vector-costs.cc
b/gcc/config/riscv/riscv-vector-costs.cc
index 70194ec70c3..9060bac8f61 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -1618,6 +1618,16 @@ costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
m_analyzed_vinfo = true;
}
+ /* For store-lanes, the middle-end passes COUNT = NCOPIES * GROUP_SIZE
+ (one per vector in the group). Normalize COUNT to segment store
+ instructions to avoid scaling the permute overhead. */
+ if (kind == vector_store)
+ {
+ int group_size = segment_loadstore_group_size (kind, stmt_info, node);
+ if (group_size > 1)
+ count = CEIL (count, group_size);
+ }
+
if (stmt_info)
{
/* If we're applying the VLA vs. VLS unrolling heuristic,
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index cd4b2bb76c2..55c2dac59f0 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -398,12 +398,12 @@ static const common_vector_cost rvv_vls_vector_cost = {
1, /* gather_load_cost */
1, /* scatter_store_cost */
1, /* segment_permute (2) */
- 1, /* segment_permute (3) */
- 1, /* segment_permute (4) */
- 1, /* segment_permute (5) */
- 1, /* segment_permute (6) */
- 1, /* segment_permute (7) */
- 1, /* segment_permute (8) */
+ 3, /* segment_permute (3) */
+ 4, /* segment_permute (4) */
+ 9, /* segment_permute (5) */
+ 10, /* segment_permute (6) */
+ 11, /* segment_permute (7) */
+ 11, /* segment_permute (8) */
1, /* vec_to_scalar_cost */
1, /* scalar_to_vec_cost */
{1, 4, 16, 64}, /* permute_cost. */
@@ -431,12 +431,12 @@ static const scalable_vector_cost rvv_vla_vector_cost = {
1, /* gather_load_cost */
1, /* scatter_store_cost */
1, /* segment_permute (2) */
- 1, /* segment_permute (3) */
- 1, /* segment_permute (4) */
- 1, /* segment_permute (5) */
- 1, /* segment_permute (6) */
- 1, /* segment_permute (7) */
- 1, /* segment_permute (8) */
+ 3, /* segment_permute (3) */
+ 4, /* segment_permute (4) */
+ 9, /* segment_permute (5) */
+ 10, /* segment_permute (6) */
+ 11, /* segment_permute (7) */
+ 11, /* segment_permute (8) */
1, /* vec_to_scalar_cost */
1, /* scalar_to_vec_cost */
{1, 4, 16, 64}, /* permute_cost. */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-1.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-1.c
index a4424f0bcad..1b17060e92d 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-1.c
@@ -21,6 +21,6 @@ f (int8_t *restrict a, int8_t *restrict b, int n)
/* FIXME: Since we don't have VECT cost model yet, LOAD_LANES/STORE_LANES are
chosen
instead of SLP when rvv-autotec-max-lmul=m1. */
-/* { dg-final { scan-tree-dump-times "\.VEC_PERM" 1 "optimized" { xfail {
any-opts "-mrvv-max-lmul=m1" } } } } */
+/* { dg-final { scan-tree-dump-times "\.VEC_PERM" 1 "optimized" } } */
/* { dg-final { scan-assembler {\tvid\.v} { xfail { any-opts
"-mrvv-max-lmul=m1" } } } } */
/* { dg-final { scan-assembler {\tvand} { xfail { any-opts "-mrvv-max-lmul=m1"
} } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-3.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-3.c
index 35659d29076..706b3795d7b 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-3.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-3.c
@@ -19,6 +19,4 @@ f (int8_t *restrict a, int8_t *restrict b, int n)
}
}
-/* FIXME: Since we don't have VECT cost model yet, LOAD_LANES/STORE_LANES are
chosen
- instead of SLP when rvv-autotec-max-lmul=m1. */
-/* { dg-final { scan-tree-dump-times "\.VEC_PERM" 1 "optimized" { xfail {
any-opts "-mrvv-max-lmul=m1" } } } } */
+/* { dg-final { scan-tree-dump-times "\.VEC_PERM" 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-5.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-5.c
index 2b2099d6e60..0391696d6be 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-5.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/slp-5.c
@@ -19,6 +19,4 @@ f (int8_t *restrict a, int8_t *restrict b, int n)
}
}
-/* FIXME: Since we don't have VECT cost model yet, LOAD_LANES/STORE_LANES are
chosen
- instead of SLP. */
-/* { dg-final { scan-tree-dump-times "\.VEC_PERM" 1 "optimized" { xfail {
any-opts "-mrvv-max-lmul=m1" "-mrvv-max-lmul=m2" } } } } */
+/* { dg-final { scan-tree-dump-times "\.VEC_PERM" 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64d-1.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64d-1.c
index 7ba1239adc2..58c30e87bfc 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64d-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64d-1.c
@@ -3,7 +3,4 @@
#include "template-1.h"
-/* With length-control for VLS modes we don't vectorize foo4 anymore.
- That's due to a very tight costing decision in the small loop.
- Therefore expect 5 instead of 6 vectorized loops. */
-/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 5 "vect"
} } */
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 6 "vect"
} } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64f-1.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64f-1.c
index e09b3989684..35da49d13d7 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64f-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/zve64f-1.c
@@ -3,7 +3,4 @@
#include "template-1.h"
-/* Same as in zve64d-1.c we don't vectorize foo4 anymore due to an
- unfortunately tight costing decision. Therefore expect 4 instead of 5
- vectorized loops. */
-/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 4 "vect"
} } */
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 5 "vect"
} } */
--
2.43.0