https://gcc.gnu.org/g:cfa4979a2c2f91c5077bf5d1c1500518581b2627
commit r17-5088-gcfa4979a2c2f91c5077bf5d1c1500518581b2627 Author: Robin Dapp <[email protected]> Date: Tue Sep 29 16:53:00 2026 +0200 RISC-V: Consider scalar loads/stores for LMUL ratio. [PR127662] Gathers and scatters get costed as scalar loads/stores. If we don't include them in the LMUL ratio calculation we're missing the load and can get ratio mismatches in different loops. This patch just adds scalar_load and scalar_store. PR target/127662 gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc (costs::record_type_sizes): Add scalar_load and scalar_store. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr127662.c: New test. Diff: --- gcc/config/riscv/riscv-vector-costs.cc | 7 ++++--- gcc/testsuite/gcc.target/riscv/rvv/autovec/pr127662.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index b7d22cb505b3..924a0330103a 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -1559,11 +1559,12 @@ costs::record_type_sizes (vect_cost_for_stmt kind, stmt_vec_info stmt_info, if (!m_largest_type || size > tree_to_uhwi (TYPE_SIZE (m_largest_type))) m_largest_type = type; - /* ??? What about scalar loads and a vec_construct or similar? */ + /* We include scalar load and store because strided and gather accesses are + costed as scalar loads. */ bool load_p = (kind == vector_load || kind == unaligned_load - || kind == vector_gather_load); + || kind == vector_gather_load || kind == scalar_load); bool store_p = (kind == vector_store || kind == unaligned_store - || kind == vector_scatter_store); + || kind == vector_scatter_store || kind == scalar_store); if ((load_p || store_p) && (!m_smallest_type || size < tree_to_uhwi (TYPE_SIZE (m_smallest_type)))) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr127662.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr127662.c new file mode 100644 index 000000000000..eac617b360c3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr127662.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d -mrvv-max-lmul=conv-dynamic" } */ + +typedef short a; +typedef struct { a b, c, d; } e; +e *f; +a g; +long h, i; +void j (void) +{ + for (; i; i++) + { + h = f[i].c / 0.5; + g = 5 * h; + f[i].c = g; + } +}
