]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PATCH] RISC-V: Fix slide pattern recognition [PR122124]
authorRaphael Moreira Zinsly <rzinsly@ventanamicro.com>
Tue, 7 Oct 2025 13:14:01 +0000 (07:14 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Tue, 7 Oct 2025 13:14:01 +0000 (07:14 -0600)
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
gcc/testsuite/gcc.target/riscv/rvv/autovec/pr122124.c [new file with mode: 0644]

index 1d7d8a61b051d3630ed38390af611a2b8c79daf4..ec713eea263b04c9dc5afe04376f25db61617616 100644 (file)
@@ -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 (file)
index 0000000..29d51b6
--- /dev/null
@@ -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" } */