Ensure the second pivot is really a pivot and it's not in OP1.

        PR target/122124
gcc/ChangeLog:
        * config/riscv/riscv-v.cc (shuffle_slide_patterns): Check if
        the second pivot is in OP1 and improve comments.

gcc/testsuite/ChangeLog:
        * gcc.target/riscv/rvv/autovec/pr122124.c: New test.
---
 gcc/config/riscv/riscv-v.cc                   |  5 +++--
 .../gcc.target/riscv/rvv/autovec/pr122124.c   | 21 +++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr122124.c

diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 1d7d8a61b05..ec713eea263 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -3779,14 +3779,15 @@ shuffle_slide_patterns (struct expand_vec_perm_d *d)
   int pivot = -1;
   for (int i = 0; i < vlen; i++)
     {
+      /* The first pivot is in OP1.  */
       if (pivot == -1 && known_ge (d->perm[i], vec_len))
        pivot = i;
       if (i > 0 && i != pivot
          && maybe_ne (d->perm[i], d->perm[i - 1] + 1))
        {
-         if (pivot == -1 || len != 0)
+         /* A second pivot would indicate the vector length and is in OP0.  */
+         if (known_ge (d->perm[i], vec_len) || pivot == -1 || len != 0)
            return false;
-         /* A second pivot would indicate the vector length.  */
          len = i;
        }
     }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr122124.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr122124.c
new file mode 100644
index 00000000000..29d51b61854
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr122124.c
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v } */
+/* { dg-additional-options "-O0 -std=gnu99" } */
+
+#include <stdint.h>
+#include <stdio.h>
+#define BS_VEC(type, num) type __attribute__((vector_size(num * sizeof(type))))
+uint16_t func_24() {
+  BS_VEC(uint32_t, 4) zero = {0};
+  BS_VEC(uint8_t, 2)
+  BS_VAR_1 = __builtin_shufflevector(
+      (BS_VEC(uint8_t, 4))5,
+      __builtin_convertvector(zero, BS_VEC(uint8_t, 4)), 5, 0);
+  return BS_VAR_1[1];
+}
+int main() {
+  printf("%u\n", func_24());
+}
+
+/* { dg-output "5" } */
-- 
2.51.0

Reply via email to