Disable unrolling for loops vectorised with non-constant VF
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Mon, 19 Nov 2018 17:58:00 +0000 (17:58 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Mon, 19 Nov 2018 17:58:00 +0000 (17:58 +0000)
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.

* tree-vect-loop.c (vect_transform_loop): Disable further unrolling
of the loop if vf is non-constant.

* gcc.target/aarch64/sve/unroll-1.c: New test.

From-SVN: r266281

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/sve/unroll-1.c [new file with mode: 0644]
gcc/tree-vect-loop.c

index 126f168a15d6b4b504a9f9bd6194cb1f6f1fb2f3..99968490f63ef1e45981d07c8c7ed5e2bb87c9f9 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * tree-vect-loop.c (vect_transform_loop): Disable further unrolling
+       of the loop if vf is non-constant.
+
 2018-11-19  David Malcolm  <dmalcolm@redhat.com>
 
        PR tree-optimization/87025
index cea66a545f1d5527d6ba4c7c6a07d8164f44b824..ba1c5d68aa0fc4ab2c6e6b42cfe10e47661215dc 100644 (file)
@@ -1,3 +1,7 @@
+2018-11-19  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * gcc.target/aarch64/sve/unroll-1.c: New test.
+
 2018-11-19  David Malcolm  <dmalcolm@redhat.com>
 
        PR tree-optimization/87025
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 (file)
index 0000000..d435300
--- /dev/null
@@ -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 } } */
index 81d8d466637ad9db24d80e034ca96327c370a65c..07a22d787c409283a5262d4cdd710fb9aa9083c2 100644 (file)
@@ -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;