]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Add autovec mode param.
authorRobin Dapp <rdapp@ventanamicro.com>
Wed, 7 May 2025 19:02:21 +0000 (21:02 +0200)
committerRobin Dapp <rdapp@ventanamicro.com>
Fri, 23 May 2025 14:59:31 +0000 (16:59 +0200)
This patch adds a --param=autovec-mode=<MODE_NAME>.  When the param is
specified we make autovectorize_vector_modes return exactly this mode if
it is available.  This helps when testing different vectorizer settings.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (autovectorize_vector_modes): Return
user-specified mode if available.
* config/riscv/riscv.opt: New param.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/param-autovec-mode.c: New test.

gcc/config/riscv/riscv-v.cc
gcc/config/riscv/riscv.opt
gcc/testsuite/gcc.target/riscv/rvv/autovec/param-autovec-mode.c [new file with mode: 0644]

index e406e7a7f59094a19035b442a99d69d6da198360..be6147b80a2cc15b99d106cb79b699267f505668 100644 (file)
@@ -2821,6 +2821,28 @@ autovectorize_vector_modes (vector_modes *modes, bool)
        i++;
        size = base_size / (1U << i);
      }
+
+  /* If the user specified the exact mode to use look if it is available and
+     remove all other ones before returning.  */
+  if (riscv_autovec_mode)
+    {
+      auto_vector_modes ms;
+      ms.safe_splice (*modes);
+      modes->truncate (0);
+
+      for (machine_mode mode : ms)
+       {
+         if (!strcmp (GET_MODE_NAME (mode), riscv_autovec_mode))
+           {
+             modes->safe_push (mode);
+             return 0;
+           }
+       }
+
+      /* Nothing found, fall back to regular handling.  */
+      modes->safe_splice (ms);
+    }
+
   /* Enable LOOP_VINFO comparison in COST model.  */
   return VECT_COMPARE_COSTS;
 }
index 527e09549a8abf70186e7b4ad77c9c97a1d3fa58..b2b9d3311f4e50aadaf0ea67fb70f382e5b08715 100644 (file)
@@ -286,6 +286,10 @@ Max number of bytes to compare as part of inlined strcmp/strncmp routines (defau
 Target RejectNegative Joined UInteger Var(gpr2vr_cost) Init(GPR2VR_COST_UNPROVIDED)
 Set the cost value of the rvv instruction when operate from GPR to VR.
 
+-param=riscv-autovec-mode=
+Target Undocumented RejectNegative Joined Var(riscv_autovec_mode) Save
+Set the only autovec mode to try.
+
 Enum
 Name(rvv_max_lmul) Type(enum rvv_max_lmul_enum)
 The RVV possible LMUL (-mrvv-max-lmul=):
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/param-autovec-mode.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/param-autovec-mode.c
new file mode 100644 (file)
index 0000000..b2ec8f9
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d --param=autovec-mode=V4QI -fdump-tree-vect-details" } */
+
+/* By default we will use RVVM1SI mode for vectorization because N is not
+   known.  Check that we use V4QI and create an epilogue when the autovec-mode
+   param is specified.  */
+
+void
+foo (int *a, int *b, int n)
+{
+  for (int i = 0; i < n; i++)
+    a[i] = b[i] + 1;
+}
+
+/* { dg-final { scan-tree-dump "Choosing vector mode V4QI" "vect" } } */
+/* { dg-final { scan-tree-dump "Choosing epilogue vector mode RVVM1SI" "vect" } } */