Hi all, This is an alternative to https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00694.html As richi suggested, this disables unrolling of loops vectorised with variable-length SVE in the vectoriser itself through the loop->unroll member.
It took me a few tries to get it right, as it needs to be set to '1' to disable unrolling, the rationale for that mechanism is described in the comment in cfgloop.h. Bootstrapped and tested on aarch64-none-linux-gnu. Is this ok for trunk? Thanks, Kyrill 2018-11-15 Kyrylo Tkachov <kyrylo.tkac...@arm.com> * tree-vect-loop.c (vect_transform_loop): Disable further unrolling of the loop if vf is non-constant. 2018-11-15 Kyrylo Tkachov <kyrylo.tkac...@arm.com> * gcc.target/aarch64/sve/unroll-1.c: New test.
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/unroll-1.c b/gcc/testsuite/gcc.target/aarch64/sve/unroll-1.c new file mode 100644 index 0000000000000000000000000000000000000000..d4353009e2145ec59b3ac74a8fc0a4a16e441581 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/unroll-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +/* Check that simple loop is not fully unrolled. */ + +void +fully_peel_me (double *x) +{ + for (int i = 0; i < 5; i++) + x[i] = x[i] * 2; +} + +/* { dg-final { scan-assembler-times {b..\t\.L.\n} 1 } } */ diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index f2d9d8ac2bc44398f955650591eea20dc7fca8a5..40d9584a00ba8d0b3fda58b3ee8df17f24432d5e 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -8515,6 +8515,15 @@ vect_transform_loop (loop_vec_info loop_vinfo) } } + /* Loops vectorized with a variable factor won't benefit from + unrolling/peeling. */ + if (!vf.is_constant ()) + { + loop->unroll = 1; + if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, "Disabling unrolling due to" + " variable-length vectorization factor\n"); + } /* Free SLP instances here because otherwise stmt reference counting won't work. */ slp_instance instance;