Hi,

Since the regmode_natural_size changes we'd spill subregs like
 (subreg:V4SI (reg:V8SI) 0)
even though a lowpart subreg is safe in a VLA setting.
This is caused by a mismatch in can_change_mode_class and
regmode_natural_size.

can_change_mode_class doesn't look at the subreg byte but would prohibit
all such subregs because we cannot statically tell whether the inner reg
is a register pair or a larger register.

A better way is to always consider VLS vectors unsplittable but don't
always prohibit them in can_change_mode_class.  That way, lowpart
subregs are still allowed but non-lowpart subregs won't
be generated in the first place.

Regtested on rva23u64.

Regards
 Robin

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_can_change_mode_class): Don't
        prohibit ambiguous VLS subregs.
        (riscv_regmode_natural_size): Make VLS regs unsplittable when
        the vector size is variable.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/autovec/vec-concat-1.c: Expect slides for
        all functions.
        * gcc.target/riscv/rvv/autovec/vls/extract-3.c: New test.
---
 gcc/config/riscv/riscv.cc                     | 17 ++------------
 .../riscv/rvv/autovec/vec-concat-1.c          |  6 +----
 .../riscv/rvv/autovec/vls/extract-3.c         | 23 +++++++++++++++++++
 3 files changed, 26 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/extract-3.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index bed695ccae4..822c6e28b33 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -13296,18 +13296,6 @@ riscv_can_change_mode_class (machine_mode from, 
machine_mode to,
       && !ordered_p (GET_MODE_PRECISION (from), GET_MODE_PRECISION (to)))
     return false;
 
-  /* Subregs of modes larger than one vector are ambiguous.
-     A V4DImode with rv64gcv_zvl128b could, for example, span two registers/one
-     register group of two at VLEN = 128 or one register at VLEN >= 256 and
-     we cannot, statically, determine which part of it to extract.
-     Therefore prevent that.  */
-  if (reg_classes_intersect_p (V_REGS, rclass)
-      && VECTOR_MODE_P (from)
-      && GET_MODE_NUNITS (from).is_constant ()
-      && maybe_ne (GET_MODE_PRECISION (from), GET_MODE_PRECISION (to))
-      && !ordered_p (BITS_PER_RISCV_VECTOR, GET_MODE_PRECISION (from)))
-      return false;
-
   return !reg_classes_intersect_p (FP_REGS, rclass);
 }
 
@@ -13734,10 +13722,9 @@ riscv_regmode_natural_size (machine_mode mode)
          if (known_lt (size, BYTES_PER_RISCV_VECTOR))
            return size;
        }
-      if (!size.is_constant ())
+      if (ordered_p (size, BYTES_PER_RISCV_VECTOR))
        return BYTES_PER_RISCV_VECTOR;
-      else
-       return TARGET_MIN_VLEN / BITS_PER_UNIT;
+      return size;
     }
   return UNITS_PER_WORD;
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vec-concat-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vec-concat-1.c
index 0fdd169bcef..8a320e1ffdc 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vec-concat-1.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vec-concat-1.c
@@ -60,9 +60,5 @@
 
 TEST_MODES (DEF_CONCAT)
 
-/* LMUL <= 1: 11 funcs x 3 slideups (using vec_concat, from spills + 1 slideup
-                                    to no spills + 3 slideups).
-   LMUL > 1:  24 funcs x 1 slideup  (no vec_concat, using fallback instead,
-                                    nothing changed from trunk).  */
-/* { dg-final { scan-assembler-times "vslideup" 57 } } */
+/* { dg-final { scan-assembler-times "vslideup" 105 } } */
 /* { dg-final { scan-assembler-not "vslide1down" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/extract-3.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/extract-3.c
new file mode 100644
index 00000000000..b6c8c913a90
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/extract-3.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2" } */
+
+typedef int v8si __attribute__ ((vector_size (32)));
+typedef int v4si __attribute__ ((vector_size (16)));
+
+void
+lo (v8si *in, v4si *out)
+{
+  v8si a = *in + *in;
+  *out = __builtin_shufflevector (a, a, 0, 1, 2, 3);
+}
+
+void
+hi (v8si *in, v4si *out)
+{
+  v8si a = *in + *in;
+  *out = __builtin_shufflevector (a, a, 4, 5, 6, 7);
+}
+
+/* { dg-final { scan-assembler-not 
{v[ls]e[0-9]+\.v\s+v[0-9]+,\s*-?[0-9]*\(sp\)} } } */
+/* { dg-final { scan-assembler-not {v[ls][0-9]r\.v} } } */
+/* { dg-final { scan-assembler-times {vslidedown\.vi} 1 } } */
-- 
2.56.0

Reply via email to