]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use max_loop_iterations in transform_to_exit_first_loop_alt
authorTom de Vries <tom@codesourcery.com>
Tue, 30 Jun 2015 08:35:57 +0000 (08:35 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Tue, 30 Jun 2015 08:35:57 +0000 (08:35 +0000)
2015-06-30  Tom de Vries  <tom@codesourcery.com>

PR tree-optimization/66652
* tree-parloops.c (try_transform_to_exit_first_loop_alt): Use
max_loop_iterations to determine if nit + 1 overflows.

* testsuite/libgomp.c/parloops-exit-first-loop-alt-3.c (f): Rewrite
using restrict pointers.
(main): Add arguments to calls to f.
* testsuite/libgomp.c/parloops-exit-first-loop-alt.c: Same.

* gcc.dg/parloops-exit-first-loop-alt-pr66652.c: New test.
* gcc.dg/parloops-exit-first-loop-alt-3.c (f):  Rewrite using restrict
pointers.
* gcc.dg/parloops-exit-first-loop-alt.c: Same.

From-SVN: r225162

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/parloops-exit-first-loop-alt-3.c
gcc/testsuite/gcc.dg/parloops-exit-first-loop-alt-pr66652.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/parloops-exit-first-loop-alt.c
gcc/tree-parloops.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c/parloops-exit-first-loop-alt-3.c
libgomp/testsuite/libgomp.c/parloops-exit-first-loop-alt.c

index 00954b1ef0818fdbd298ff5bc9ec39d06f86131c..9b8c7cff39952904cf124e6133c782f89ef79746 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-30  Tom de Vries  <tom@codesourcery.com>
+
+       PR tree-optimization/66652
+       * tree-parloops.c (try_transform_to_exit_first_loop_alt): Use
+       max_loop_iterations to determine if nit + 1 overflows.
+
 2015-06-30  Richard Biener  <rguenther@suse.de>
 
        * tree-vrp.c (register_edge_assert_for_2): Also register
index 9c2f20b2c72db1bdb7f9242cfd126863eb97041b..f249a7d7ded7cefc6de69e6e0ebe71f679ebbf0f 100644 (file)
@@ -1,3 +1,11 @@
+2015-06-30  Tom de Vries  <tom@codesourcery.com>
+
+       PR tree-optimization/66652
+       * gcc.dg/parloops-exit-first-loop-alt-pr66652.c: New test.
+       * gcc.dg/parloops-exit-first-loop-alt-3.c (f):  Rewrite using restrict
+       pointers.
+       * gcc.dg/parloops-exit-first-loop-alt.c: Same.
+
 2015-06-29  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/65977
index b0fde372a141f4bd030e29c2f059e9aedbf7db07..fec53a19628acdf08fef7b8b2b152249292740eb 100644 (file)
@@ -7,7 +7,7 @@
 unsigned int *a;
 
 unsigned int
-f (unsigned int n)
+f (unsigned int n, unsigned int *__restrict__ a)
 {
   int i;
   unsigned int sum = 1;
diff --git a/gcc/testsuite/gcc.dg/parloops-exit-first-loop-alt-pr66652.c b/gcc/testsuite/gcc.dg/parloops-exit-first-loop-alt-pr66652.c
new file mode 100644 (file)
index 0000000..2ea097d
--- /dev/null
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O2 -ftree-parallelize-loops=2 -fdump-tree-parloops" } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+unsigned int
+f (unsigned int n, unsigned int sum)
+{
+  unsigned int i;
+
+  i = UINT_MAX;
+  do
+    {
+      sum += i % 13;
+      i++;
+    }
+  while (i < n - 1);
+
+  return sum;
+}
+
+/* Four times % 13:
+   - once in f._loopfn.0
+   - once in the parallel
+   - once in the low iteration count loop
+   - once for a peeled off last iteration following the parallel.
+   In other words, we want try_transform_to_exit_first_loop_alt to fail.  */
+/* { dg-final { scan-tree-dump-times "(?n)% 13" 4 "parloops" } } */
index b36f01b8f8f3284290f47562ebe53a6c2d15232e..e088fa110b398942b3e3871fd1dc606c453af495 100644 (file)
@@ -4,14 +4,9 @@
 
 /* Variable bound, vector addition.  */
 
-#define N 1000
-
-unsigned int a[N];
-unsigned int b[N];
-unsigned int c[N];
-
 void
-f (unsigned int n)
+f (unsigned int n, unsigned int *__restrict__ a, unsigned int *__restrict__ b,
+   unsigned int *__restrict__ c)
 {
   int i;
 
@@ -19,9 +14,9 @@ f (unsigned int n)
     c[i] = a[i] + b[i];
 }
 
-/* Three times three array accesses:
-   - three in f._loopfn.0
-   - three in the parallel
-   - three in the low iteration count loop
+/* Three times a store:
+   - one in f._loopfn.0
+   - one in the parallel
+   - one in the low iteration count loop
    Crucially, none for a peeled off last iteration following the parallel.  */
-/* { dg-final { scan-tree-dump-times "(?n)\\\[i" 9 "parloops" } } */
+/* { dg-final { scan-tree-dump-times "(?n)^  \\*_\[0-9\]*" 3 "parloops" } } */
index ec708c67ac97306265061b739ae47722d7290112..21ed17b4cafde79e04603b4cfd239bd30d06a7b2 100644 (file)
@@ -1801,8 +1801,39 @@ try_transform_to_exit_first_loop_alt (struct loop *loop,
 
   gcc_assert (TREE_CODE (nit) == SSA_NAME);
 
+  /* Variable nit is the loop bound as returned by canonicalize_loop_ivs, for an
+     iv with base 0 and step 1 that is incremented in the latch, like this:
+
+     <bb header>:
+     # iv_1 = PHI <0 (preheader), iv_2 (latch)>
+     ...
+     if (iv_1 < nit)
+       goto <bb latch>;
+     else
+       goto <bb exit>;
+
+     <bb latch>:
+     iv_2 = iv_1 + 1;
+     goto <bb header>;
+
+     The range of iv_1 is [0, nit].  The latch edge is taken for
+     iv_1 == [0, nit - 1] and the exit edge is taken for iv_1 == nit.  So the
+     number of latch executions is equal to nit.
+
+     The function max_loop_iterations gives us the maximum number of latch
+     executions, so it gives us the maximum value of nit.  */
+  widest_int nit_max;
+  if (!max_loop_iterations (loop, &nit_max))
+    return false;
+
+  /* Check if nit + 1 overflows.  */
+  widest_int type_max = wi::to_widest (TYPE_MAXVAL (nit_type));
+  if (!wi::lts_p (nit_max, type_max))
+    return false;
+
   gimple def = SSA_NAME_DEF_STMT (nit);
 
+  /* Try to find nit + 1, in the form of n in an assignment nit = n - 1.  */
   if (def
       && is_gimple_assign (def)
       && gimple_assign_rhs_code (def) == PLUS_EXPR)
index a01f9b2816c4117d4e04fd15ba3e98c7a62e71fc..2c539b821aca606670eaae7cb0c58e1a8c463918 100644 (file)
@@ -1,3 +1,11 @@
+2015-06-30  Tom de Vries  <tom@codesourcery.com>
+
+       PR tree-optimization/66652
+       * testsuite/libgomp.c/parloops-exit-first-loop-alt-3.c (f): Rewrite
+       using restrict pointers.
+       (main): Add arguments to calls to f.
+       * testsuite/libgomp.c/parloops-exit-first-loop-alt.c: Same.
+
 2015-06-23  Andreas Tobler  <andreast@gcc.gnu.org>
 
        * configure.ac: Fix check for header <sys/sysctl.h>.
index cb5bf9cb8c575d35a08e06213d73fb3f1a53f197..7de1377cd56956f8552fa29be0571d5f5d366f88 100644 (file)
@@ -10,7 +10,7 @@
 unsigned int *a;
 
 unsigned int __attribute__((noclone,noinline))
-f (unsigned int n)
+f (unsigned int n, unsigned int *__restrict__ a)
 {
   int i;
   unsigned int sum = 1;
@@ -32,7 +32,7 @@ main (void)
     array[i] = i % 7;
   a = &array[0];
 
-  res = f (N);
+  res = f (N, a);
   if (res != 11995)
     abort ();
 
index 1c32ea33f7b0bae922ff09345bdd6abf7edc391f..07468a9ab9e75a5685992b6187e462b2dafcae3a 100644 (file)
@@ -13,7 +13,8 @@ unsigned int b[N];
 unsigned int c[N];
 
 void __attribute__((noclone,noinline))
-f (unsigned int n)
+f (unsigned int n, unsigned int *__restrict__ a, unsigned int *__restrict__ b,
+   unsigned int *__restrict__ c)
 {
   int i;
 
@@ -36,7 +37,7 @@ main (void)
        c[k] = k * 2;
       }
 
-  f (N);
+  f (N, a, b, c);
 
   for (i = 0; i < N; i++)
     {