Could you make a simple testcase that could vectorize two loops in different modes (e.g one SI and one SF) and with this param will only auto vec on loop?
I added a test now in the attached v2 that checks that we vectorize with the requested mode. Right now the patch only takes away "additional" vector modes (like V4QI) and not the first vector mode that we always have (e.g. RVVM1SF).
Maybe I should change the doc string still? But technically, it's undocumented ;)
Regards Robin 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 | 22 +++++++++++++++++++ gcc/config/riscv/riscv.opt | 4 ++++ .../riscv/rvv/autovec/param-autovec-mode.c | 16 ++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/param-autovec-mode.c diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 1b5ef51886e..cb643389bb9 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 527e09549a8..5b6dbc6bb4e 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=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 00000000000..b2ec8f9dc77 --- /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" } } */ -- 2.49.0