The vectorizer picks up these loops and disables unrolling on targets with variable vector factors. That result in better code here, but it trips up the unrolling tests. So just disable vectorization for these.
gcc/testsuite/ChangeLog: PR target/112531 * gcc.dg/unroll-8.c: Disable vectorization on arm64 and riscv. --- This also isn't tested. --- gcc/testsuite/gcc.dg/unroll-8.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/testsuite/gcc.dg/unroll-8.c b/gcc/testsuite/gcc.dg/unroll-8.c index 06d32e56893..4465c620800 100644 --- a/gcc/testsuite/gcc.dg/unroll-8.c +++ b/gcc/testsuite/gcc.dg/unroll-8.c @@ -1,6 +1,15 @@ /* { dg-do compile } */ /* { dg-options "-O2 -fdump-rtl-loop2_unroll-details-blocks -funroll-loops" } */ + +/* + * Targets that support variable-length vectorization don't unroll loops (see + * the "Disabling unrolling due to variable-length vectorization factor" out in + * tree-vect-loop. So disable tree vectorization for these targets, as it will + * interfere with the unrolling we're looking for below. + */ +/* { dg-additional-options "-fno-tree-vectorize" { target aarch64-*-* } } */ /* { dg-additional-options "-fno-tree-vectorize" { target amdgcn-*-* } } */ +/* { dg-additional-options "-fno-tree-vectorize" { target riscv*-*-* } } */ struct a {int a[7];}; void t(struct a *a, int n) -- 2.42.1