Hi,

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.

Regtested on rv64gcv_zvl512b.  Pushing as obvious.

Regards
 Robin

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.
---
 gcc/config/riscv/riscv-vector-costs.cc          |  7 ++++---
 .../gcc.target/riscv/rvv/autovec/pr127662.c     | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr127662.c

diff --git a/gcc/config/riscv/riscv-vector-costs.cc 
b/gcc/config/riscv/riscv-vector-costs.cc
index b7d22cb505b..924a0330103 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 00000000000..eac617b360c
--- /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;
+    }
+}
-- 
2.55.0

Reply via email to