public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1181] vect: Use main loop's thresholds and VF to narrow upper_bound of epilogue
@ 2021-06-03 12:57 Andre Simoes Dias Vieira
  0 siblings, 0 replies; only message in thread
From: Andre Simoes Dias Vieira @ 2021-06-03 12:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7ed1cd9665d8ca0fa07b2483e604c25e704584af

commit r12-1181-g7ed1cd9665d8ca0fa07b2483e604c25e704584af
Author: Andre Vieira <andre.simoesdiasvieira@arm.com>
Date:   Thu Jun 3 13:55:24 2021 +0100

    vect: Use main loop's thresholds and VF to narrow upper_bound of epilogue
    
    This patch uses the knowledge of the conditions to enter an epilogue loop to
    help come up with a potentially more restricive upper bound.
    
    gcc/ChangeLog:
    
            * tree-vect-loop.c (vect_transform_loop): Use main loop's various'
            thresholds to narrow the upper bound on epilogue iterations.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/sve/part_vect_single_iter_epilog.c: New test.

Diff:
---
 .../aarch64/sve/part_vect_single_iter_epilog.c     | 11 ++++++++
 gcc/tree-vect-loop.c                               | 31 +++++++++++++++++-----
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
new file mode 100644
index 00000000000..a03229eb555
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 --param vect-partial-vector-usage=1" } */
+
+void
+foo (short * __restrict__ a, short * __restrict__ b, short * __restrict__ c, int n)
+{
+  for (int i = 0; i < n; ++i)
+    c[i] = a[i] + b[i];
+}
+
+/* { dg-final { scan-assembler-times {\twhilelo\tp[0-9]+.h, wzr, [xw][0-9]+} 1 } } */
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index ff7673d7250..ba36348b835 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -9740,12 +9740,31 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple *loop_vectorized_call)
   /* In these calculations the "- 1" converts loop iteration counts
      back to latch counts.  */
   if (loop->any_upper_bound)
-    loop->nb_iterations_upper_bound
-      = (final_iter_may_be_partial
-	 ? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
-			  lowest_vf) - 1
-	 : wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
-			   lowest_vf) - 1);
+    {
+      loop_vec_info main_vinfo = LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo);
+      loop->nb_iterations_upper_bound
+	= (final_iter_may_be_partial
+	   ? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
+			    lowest_vf) - 1
+	   : wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
+			     lowest_vf) - 1);
+      if (main_vinfo)
+	{
+	  unsigned int bound;
+	  poly_uint64 main_iters
+	    = upper_bound (LOOP_VINFO_VECT_FACTOR (main_vinfo),
+			   LOOP_VINFO_COST_MODEL_THRESHOLD (main_vinfo));
+	  main_iters
+	    = upper_bound (main_iters,
+			   LOOP_VINFO_VERSIONING_THRESHOLD (main_vinfo));
+	  if (can_div_away_from_zero_p (main_iters,
+					LOOP_VINFO_VECT_FACTOR (loop_vinfo),
+					&bound))
+	    loop->nb_iterations_upper_bound
+	      = wi::umin ((widest_int) (bound - 1),
+			  loop->nb_iterations_upper_bound);
+      }
+  }
   if (loop->any_likely_upper_bound)
     loop->nb_iterations_likely_upper_bound
       = (final_iter_may_be_partial


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-03 12:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 12:57 [gcc r12-1181] vect: Use main loop's thresholds and VF to narrow upper_bound of epilogue Andre Simoes Dias Vieira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).