https://gcc.gnu.org/g:15cc995ae507e4a5f8ace9e9cb6941943ddc2153
commit 15cc995ae507e4a5f8ace9e9cb6941943ddc2153 Author: Robin Dapp <rd...@ventanamicro.com> Date: Wed May 7 21:02:21 2025 +0200 RISC-V: Add autovec mode param. 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. (cherry picked from commit b949d048e914a4cd11a63004a9a2d42e51bc3ac8) Diff: --- gcc/config/riscv/riscv-v.cc | 22 ++++++++++++++++++++++ gcc/config/riscv/riscv.opt | 4 ++++ .../riscv/rvv/autovec/param-autovec-mode.c | 16 ++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index e406e7a7f590..be6147b80a2c 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -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; } diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 527e09549a8a..b2b9d3311f4e 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -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 index 000000000000..b2ec8f9dc774 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/param-autovec-mode.c @@ -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" } } */