@@ -3807,6 +3807,9 @@ riscv_pragma_intrinsic_flags_pollute (struct pragma_intrinsic_flags *flags)
flags->intrinsic_riscv_zvl_subext = riscv_zvl_subext;
flags->intrinsic_riscv_zvf_subext = riscv_zvf_subext;
+ /* At 4096 the fallback types would alias valid ones; keep VLEN >= 64. */
+ unsigned real_min_vlen = TARGET_VECTOR ? TARGET_MIN_VLEN : 0;
+
riscv_zvf_subext = riscv_zvf_subext
| MASK_ZVFBFMIN
| MASK_ZVFHMIN;
@@ -3817,15 +3820,16 @@ riscv_pragma_intrinsic_flags_pollute (struct pragma_intrinsic_flags *flags)
riscv_base_subext = riscv_base_subext
| MASK_MUL;
- riscv_zvl_subext = riscv_zvl_subext
- | MASK_ZVL32B
- | MASK_ZVL64B
- | MASK_ZVL128B
- | MASK_ZVL256B
- | MASK_ZVL512B
- | MASK_ZVL1024B
- | MASK_ZVL2048B
- | MASK_ZVL4096B;
+ if (real_min_vlen < 64)
+ riscv_zvl_subext = riscv_zvl_subext
+ | MASK_ZVL32B
+ | MASK_ZVL64B
+ | MASK_ZVL128B
+ | MASK_ZVL256B
+ | MASK_ZVL512B
+ | MASK_ZVL1024B
+ | MASK_ZVL2048B
+ | MASK_ZVL4096B;
riscv_vector_elen_flags = riscv_vector_elen_flags
| MASK_VECTOR_ELEN_32
new file mode 100644
@@ -0,0 +1,11 @@
+/* PR target/126803 */
+/* { dg-do compile } */
+/* { dg-options "-march=rv32imf_zve32f_zvl128b -mabi=ilp32f -O2" } */
+
+#include <riscv_vector.h>
+
+vfloat32m1_t
+identity (vfloat32m1_t value)
+{
+ return value;
+}
new file mode 100644
@@ -0,0 +1,11 @@
+/* PR target/126803 */
+/* { dg-do compile } */
+/* { dg-options "-std=c++17 -march=rv64imafc_zve32f_zvl256b -mabi=lp64f" } */
+
+#include <riscv_vector.h>
+
+vfloat32m1_t
+identity (vfloat32m1_t value)
+{
+ return value;
+}
new file mode 100644
@@ -0,0 +1,11 @@
+/* PR target/126803 */
+/* { dg-do compile } */
+/* { dg-options "-march=rv32im_zve32x_zvl1024b -mabi=ilp32 -O2" } */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+identity (vint32m1_t value)
+{
+ return value;
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/* PR target/126803 */
+/* { dg-do compile } */
+/* { dg-options "-march=rv32im_zve32x_zvl64b -mabi=ilp32 -O2" } */
+
+/* At VLEN 64 the valid vint8m8_t and vbool1_t have 64 elements. The
+ masked overload of __riscv_vle8 for them must not be merged with the
+ one for vint8mf8_t and vbool64_t, which need ELEN 64. */
+
+#include <riscv_vector.h>
+
+vint8m8_t
+f (vbool1_t m, const int8_t *p, size_t vl)
+{
+ return __riscv_vle8 (m, p, vl);
+}
+
+vint8m4_t
+g (vbool2_t m, const int8_t *p, size_t vl)
+{
+ return __riscv_vle8 (m, p, vl);
+}
+
+/* { dg-final { scan-assembler {e8,\s*m8} } } */
+/* { dg-final { scan-assembler {e8,\s*m4} } } */
RVV types are registered in two passes. register_builtin_types creates the types that are valid for the TU's -march. The rvv_switcher used by handle_pragma_vector then pollutes the ISA flags and creates the remaining types in register_builtin_types_on_null. The pollution also sets zvl32b..zvl4096b, so the second pass uses a minimum VLEN of 4096 while the first one used the real one. A type with SEW/LMUL R has MIN_VLEN/R elements. With ELEN 32 the valid types have R <= 32, and the polluted ones include R = 64. A polluted R = 64 type therefore has 4096/64 = 64 elements. That equals the element count of a valid type with R = V/64 for every VLEN V from 64 to 2048. The C++ front end compares RVV types structurally, so two types with the same element type and element count are the same type, e.g. vuint8m2_t and vuint8mf8_t at zvl256b. Overloads that differ only in those types then clash: error: ambiguating new declaration of 'vfloat16m4_t __riscv_vluxei8(const _Float16*, vuint8m2_t, long unsigned int)' At zvl64b the return types collide as well, so the overloads for vint8m8_t/vbool1_t and vint8mf8_t/vbool64_t are merged silently. A valid masked __riscv_vle8 on vint8m8_t then resolves to the mf8 instance and fails with "requires the zve64x, zve64f, zve64d or v ISA extension". Keep the real minimum vector length during the pollution when it is at least 64. The polluted R = 64 types then have V/64 elements and the valid types at least V/32, so no two RVV types with the same element type share an element count. Use 4096 as before when there is no vector extension, or for VLEN 32: there the valid types have at most 32 elements, and ELEN 64 needs a VLEN of at least 64. The ELEN, FP16, BF16 and other flag pollution is unchanged, so the same types and functions are registered in the same order. PR target/126803 gcc/ChangeLog: * config/riscv/riscv-vector-builtins.cc (riscv_pragma_intrinsic_flags_pollute): Keep the real minimum vector length when it is at least 64. gcc/testsuite/ChangeLog: * g++.target/riscv/rvv/base/pr126803-1.C: New test. * g++.target/riscv/rvv/base/pr126803-2.C: New test. * g++.target/riscv/rvv/base/pr126803-3.C: New test. * g++.target/riscv/rvv/base/pr126803-4.C: New test. Signed-off-by: Kansei Motoe <kan.mo.def@gmail.com> --- gcc/config/riscv/riscv-vector-builtins.cc | 22 ++++++++++------- .../g++.target/riscv/rvv/base/pr126803-1.C | 11 +++++++++ .../g++.target/riscv/rvv/base/pr126803-2.C | 11 +++++++++ .../g++.target/riscv/rvv/base/pr126803-3.C | 11 +++++++++ .../g++.target/riscv/rvv/base/pr126803-4.C | 24 +++++++++++++++++++ 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/pr126803-1.C create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/pr126803-2.C create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/pr126803-3.C create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/pr126803-4.C