loop-unroll.c (decide_unroll_constant_iterations, [...]): Use likely upper bounds.
authorJan Hubicka <hubicka@ucw.cz>
Wed, 1 Jun 2016 12:01:17 +0000 (14:01 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Wed, 1 Jun 2016 12:01:17 +0000 (12:01 +0000)
* loop-unroll.c (decide_unroll_constant_iterations,
decide_unroll_runtime_iterations, decide_unroll_stupid): Use
likely upper bounds.
* loop-iv.c (find_simple_exit): Dump likely upper bounds.

* gcc.dg/unroll-6.c: Update template.
* gcc.dg/unroll-7.c: New testcase.
* gcc.dg/unroll-8.c: New testcase.

From-SVN: r236986

gcc/ChangeLog
gcc/loop-iv.c
gcc/loop-unroll.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/unroll-6.c
gcc/testsuite/gcc.dg/unroll-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/unroll-8.c [new file with mode: 0644]

index 58fea2fca683b972fd843eed9ec2eab4e855a8e1..d7321aeff2f39666a3d54d064ec3d9fa3165c6ae 100644 (file)
@@ -1,3 +1,10 @@
+2016-06-01  Jan Hubicka  <hubicka@ucw.cz>
+
+       * loop-unroll.c (decide_unroll_constant_iterations,
+       decide_unroll_runtime_iterations, decide_unroll_stupid): Use
+       likely upper bounds.
+       * loop-iv.c (find_simple_exit): Dump likely upper bounds.
+
 2016-06-01  Thomas Schwinge  <thomas@codesourcery.com>
 
        * tree-core.h (enum omp_clause_code): Remove
index fecaf8f110acb4afb4a697451eabf6b493ca1e20..57fb8c1fa7f116682fc39745b7aa7592387f8a59 100644 (file)
@@ -2998,6 +2998,8 @@ find_simple_exit (struct loop *loop, struct niter_desc *desc)
 
          fprintf (dump_file, "  upper bound: %li\n",
                   (long)get_max_loop_iterations_int (loop));
+         fprintf (dump_file, "  likely upper bound: %li\n",
+                  (long)get_likely_max_loop_iterations_int (loop));
          fprintf (dump_file, "  realistic bound: %li\n",
                   (long)get_estimated_loop_iterations_int (loop));
        }
index 97735a89e5876188ce697554ae9bd5164bef0eeb..42b1548d1ffa9f0967e95e0d596ac4c638754465 100644 (file)
@@ -396,7 +396,7 @@ decide_unroll_constant_iterations (struct loop *loop, int flags)
      of iterations.  */
   if (desc->niter < 2 * nunroll
       || ((get_estimated_loop_iterations (loop, &iterations)
-          || get_max_loop_iterations (loop, &iterations))
+          || get_likely_max_loop_iterations (loop, &iterations))
          && wi::ltu_p (iterations, 2 * nunroll)))
     {
       if (dump_file)
@@ -706,7 +706,7 @@ decide_unroll_runtime_iterations (struct loop *loop, int flags)
 
   /* Check whether the loop rolls.  */
   if ((get_estimated_loop_iterations (loop, &iterations)
-       || get_max_loop_iterations (loop, &iterations))
+       || get_likely_max_loop_iterations (loop, &iterations))
       && wi::ltu_p (iterations, 2 * nunroll))
     {
       if (dump_file)
@@ -1162,7 +1162,7 @@ decide_unroll_stupid (struct loop *loop, int flags)
 
   /* Check whether the loop rolls.  */
   if ((get_estimated_loop_iterations (loop, &iterations)
-       || get_max_loop_iterations (loop, &iterations))
+       || get_likely_max_loop_iterations (loop, &iterations))
       && wi::ltu_p (iterations, 2 * nunroll))
     {
       if (dump_file)
index fc864d35b6debd420d500a27a6dd88a458eeeae0..75d8504da76281dd67a4bf3f4c57914e07a1c3fd 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-01  Jan Hubicka  <hubicka@ucw.cz>
+
+       * gcc.dg/unroll-6.c: Update template.
+       * gcc.dg/unroll-7.c: New testcase.
+       * gcc.dg/unroll-8.c: New testcase.
+
 2016-06-01  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/opt56.ad[sb]: New test.
index 8e8b7264fcd8af30dc27ceaf013b9fc6e8156865..e4c231ea79f6d6d4b3d74082a65f18c6976d8d9d 100644 (file)
@@ -28,7 +28,7 @@ int t2()
         abort ();
   return 0;
 }
-/* { dg-final { scan-rtl-dump-times "upper bound: 999999" 1 "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump-times "  upper bound: 999999" 1 "loop2_unroll" } } */
 /* { dg-final { scan-rtl-dump-not "realistic bound: 999999" "loop2_unroll" } } */
-/* { dg-final { scan-rtl-dump-times "upper bound: 2999999" 1 "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump-times "  upper bound: 2999999" 1 "loop2_unroll" } } */
 /* { dg-final { scan-rtl-dump-times "realistic bound: 2999999" 1 "loop2_unroll" } } */
diff --git a/gcc/testsuite/gcc.dg/unroll-7.c b/gcc/testsuite/gcc.dg/unroll-7.c
new file mode 100644 (file)
index 0000000..e7fa4cf
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-loop2_unroll -funroll-loops" } */
+int t(int *a)
+{
+  int i;
+  for (i=0;i<1000000;i++)
+    a[i]++;
+}
+/* { dg-final { scan-rtl-dump "Unrolled loop" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "number of iterations: .const_int 999999" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "upper bound: 999999" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "realistic bound: 999999" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "Considering unrolling loop with constant number of iterations" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump-not "Invalid sum" "loop2_unroll" } } */
diff --git a/gcc/testsuite/gcc.dg/unroll-8.c b/gcc/testsuite/gcc.dg/unroll-8.c
new file mode 100644 (file)
index 0000000..b16df67
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-loop2_unroll -funroll-loops" } */
+struct a {int a[7];};
+int t(struct a *a, int n)
+{
+  int i;
+  for (i=0;i<n;i++)
+    a->a[i]++;
+}
+/* { dg-final { scan-rtl-dump-not "Unrolled loop" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "likely upper bound: 7" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "realistic bound: -1" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump "Not unrolling loop, doesn't roll" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump-not "Invalid sum" "loop2_unroll" } } */
+/* { dg-final { scan-rtl-dump-not "upper bound: -1" "loop2_unroll" } } */