]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/44688 (Excessive code-size growth at -O3)
authorRichard Guenther <rguenther@suse.de>
Thu, 19 Apr 2012 08:51:50 +0000 (08:51 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 19 Apr 2012 08:51:50 +0000 (08:51 +0000)
2012-04-19  Richard Guenther  <rguenther@suse.de>

PR rtl-optimization/44688
* loop-iv.c (determine_max_iter): Only return max_iter.
(iv_number_of_iterations): Also use the recorded loop bound
on the maximum number of iterations.
* loop-unroll.c (decide_unroll_runtime_iterations): Use
max_iter to avoid unrolling loops that do not roll.
(decide_unroll_stupid): Likewise.

* gcc.dg/var-expand1.c: Increase array size to make unrolling
possibly profitable.

From-SVN: r186585

gcc/ChangeLog
gcc/loop-iv.c
gcc/loop-unroll.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/var-expand1.c

index fb7a2c348a6575191675f611f2d1721ee6156b98..f2a9e0ae29fc7f77cec5cd8dcb796f381d09bdd0 100644 (file)
@@ -1,3 +1,13 @@
+2012-04-19  Richard Guenther  <rguenther@suse.de>
+
+       PR rtl-optimization/44688
+       * loop-iv.c (determine_max_iter): Only return max_iter.
+       (iv_number_of_iterations): Also use the recorded loop bound
+       on the maximum number of iterations.
+       * loop-unroll.c (decide_unroll_runtime_iterations): Use
+       max_iter to avoid unrolling loops that do not roll.
+       (decide_unroll_stupid): Likewise.
+
 2012-04-18  Steven Bosscher  <steven@gcc.gnu.org>
 
        * targhooks.c (default_case_values_threshold): Fix code style nit.
index 83d25015976875746ef0fc71fe793ba1b2b7577c..382d4ce1591170c57e02d529fb84ed5ac53270d1 100644 (file)
@@ -2190,8 +2190,8 @@ canonicalize_iv_subregs (struct rtx_iv *iv0, struct rtx_iv *iv1,
   return true;
 }
 
-/* Tries to estimate the maximum number of iterations in LOOP, and store the
-   result in DESC.  This function is called from iv_number_of_iterations with
+/* Tries to estimate the maximum number of iterations in LOOP, and return the
+   result.  This function is called from iv_number_of_iterations with
    a number of fields in DESC already filled in.  OLD_NITER is the original
    expression for the number of iterations, before we tried to simplify it.  */
 
@@ -2207,10 +2207,7 @@ determine_max_iter (struct loop *loop, struct niter_desc *desc, rtx old_niter)
     {
       nmax = INTVAL (XEXP (niter, 0));
       if (!(nmax & (nmax + 1)))
-       {
-         desc->niter_max = nmax;
-         return nmax;
-       }
+       return nmax;
     }
 
   get_mode_bounds (desc->mode, desc->signed_p, desc->mode, &mmin, &mmax);
@@ -2219,10 +2216,7 @@ determine_max_iter (struct loop *loop, struct niter_desc *desc, rtx old_niter)
   if (GET_CODE (niter) == UDIV)
     {
       if (!CONST_INT_P (XEXP (niter, 1)))
-       {
-         desc->niter_max = nmax;
-         return nmax;
-       }
+       return nmax;
       inc = INTVAL (XEXP (niter, 1));
       niter = XEXP (niter, 0);
     }
@@ -2241,7 +2235,6 @@ determine_max_iter (struct loop *loop, struct niter_desc *desc, rtx old_niter)
       if (dump_file)
        fprintf (dump_file, ";; improved upper bound by one.\n");
     }
-  desc->niter_max = nmax / inc;
   return nmax / inc;
 }
 
@@ -2259,7 +2252,7 @@ iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
   enum rtx_code cond;
   enum machine_mode mode, comp_mode;
   rtx mmin, mmax, mode_mmin, mode_mmax;
-  unsigned HOST_WIDEST_INT s, size, d, inv;
+  unsigned HOST_WIDEST_INT s, size, d, inv, max;
   HOST_WIDEST_INT up, down, inc, step_val;
   int was_sharp = false;
   rtx old_niter;
@@ -2279,6 +2272,9 @@ iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
   desc->const_iter = false;
   desc->niter_expr = NULL_RTX;
   desc->niter_max = 0;
+  if (loop->any_upper_bound
+      && double_int_fits_in_uhwi_p (loop->nb_iterations_upper_bound))
+    desc->niter_max = loop->nb_iterations_upper_bound.low;
 
   cond = GET_CODE (condition);
   gcc_assert (COMPARISON_P (condition));
@@ -2547,7 +2543,10 @@ iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
          down = INTVAL (CONST_INT_P (iv0.base)
                         ? iv0.base
                         : mode_mmin);
-         desc->niter_max = (up - down) / inc + 1;
+         max = (up - down) / inc + 1;
+         if (!desc->niter_max
+             || max < desc->niter_max)
+           desc->niter_max = max;
 
          if (iv0.step == const0_rtx)
            {
@@ -2762,8 +2761,10 @@ iv_number_of_iterations (struct loop *loop, rtx insn, rtx condition,
     }
   else
     {
-      if (!desc->niter_max)
-       desc->niter_max = determine_max_iter (loop, desc, old_niter);
+      max = determine_max_iter (loop, desc, old_niter);
+      if (!desc->niter_max
+         || max < desc->niter_max)
+       desc->niter_max = max;
 
       /* simplify_using_initial_values does a copy propagation on the registers
         in the expression for the number of iterations.  This prolongs life
index 5a658d85bcbf80b7c5b61a18c96fd389b5015d37..f251f5dbacd0361b8b461a2177d8dd1e636435de 100644 (file)
@@ -857,7 +857,9 @@ decide_unroll_runtime_iterations (struct loop *loop, int flags)
     }
 
   /* If we have profile feedback, check whether the loop rolls.  */
-  if (loop->header->count && expected_loop_iterations (loop) < 2 * nunroll)
+  if ((loop->header->count
+       && expected_loop_iterations (loop) < 2 * nunroll)
+      || desc->niter_max < 2 * nunroll)
     {
       if (dump_file)
        fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
@@ -1400,8 +1402,9 @@ decide_unroll_stupid (struct loop *loop, int flags)
     }
 
   /* If we have profile feedback, check whether the loop rolls.  */
-  if (loop->header->count
-      && expected_loop_iterations (loop) < 2 * nunroll)
+  if ((loop->header->count
+       && expected_loop_iterations (loop) < 2 * nunroll)
+      || desc->niter_max < 2 * nunroll)
     {
       if (dump_file)
        fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
index a07a031a4a78ea6c12a0edde29804de758e71a77..6d9506edb273333706f8c06640f10308846eadf9 100644 (file)
@@ -1,3 +1,9 @@
+2012-04-19  Richard Guenther  <rguenther@suse.de>
+
+       PR rtl-optimization/44688
+       * gcc.dg/var-expand1.c: Increase array size to make unrolling
+       possibly profitable.
+
 2012-04-18  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        PR tree-optimization/52976
index 3904407c44d41baa2a73dd1015d09b9269f852a7..a784ea1a0416b6ec07f2a1ec865419887e2485ef 100644 (file)
@@ -6,7 +6,7 @@
 
 extern void abort (void);
 
-float array[10] = { 1,2,3,4,5,6,7,8,9,10 };
+float array[30] = { 1,2,3,4,5,6,7,8,9,10 };
 
 int foo (int n)
 {