Patchwork [committed] : Fix PR 46675, Profiledbootstrap failed

login
register
mail settings
Submitter Uros Bizjak
Date Nov. 29, 2010, 5:19 p.m.
Message ID <AANLkTikQ5L+hQykzWUguuvtmKXJo+7on7xa=HO6u2gCu@mail.gmail.com>
Download mbox | patch
Permalink /patch/73460/
State New
Headers show

Comments

Uros Bizjak - Nov. 29, 2010, 5:19 p.m.
On Mon, Nov 29, 2010 at 6:17 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> Hello!
>
> The fix is by Zdenek:
>
> Fixes overflow in # of iterations analysis -- when splitting var - INT_MIN to a
> sum of a variable part and a constant offset, we performed the negation of the
> offset in the original type (which overflows for INT_MIN) instead of in full
> precision.
>
> 2010-11-29  Zdenek Dvorak  <rakdver@kam.uniff.cz>
>
>        PR tree-optimization/46675
>        * tree-ssa-loop-niter.c (split_to_var_and_offset): Avoid overflow
>        in offset calculation.
>
> testsuite/ChangeLog:
>
> 2010-11-29  Richard Guenther  <rguenther@suse.de>
>            Zdenek Dvorak  <rakdver@kam.uniff.cz>
>
>        PR tree-optimization/46675
>        * gcc.dg/pr46675.c: New test.
>
> Patch was tested on x86_64-pc-linux-gnu {,-m32} with a profiled
> bootstrap of all default languages.
>
> The patch was approved by Richi in the PR as obvious and was committed
> to SVN mainline.
>
> BTW: H.J. has set a profiledbootstrap tester on gnu-16.sc... host, see
> current results at [1].
>
> [1] http://gcc.gnu.org/ml/gcc-testresults/2010-11/msg02438.html

Now with the patch attached.

Uros.

Patch

Index: tree-ssa-loop-niter.c
===================================================================
--- tree-ssa-loop-niter.c	(revision 167252)
+++ tree-ssa-loop-niter.c	(working copy)
@@ -95,10 +95,10 @@  split_to_var_and_offset (tree expr, tree
       *var = op0;
       /* Always sign extend the offset.  */
       off = tree_to_double_int (op1);
-      if (negate)
-	off = double_int_neg (off);
       off = double_int_sext (off, TYPE_PRECISION (type));
       mpz_set_double_int (offset, off, false);
+      if (negate)
+	mpz_neg (offset, offset);
       break;
 
     case INTEGER_CST:
Index: testsuite/gcc.dg/pr46675.c
===================================================================
--- testsuite/gcc.dg/pr46675.c	(revision 0)
+++ testsuite/gcc.dg/pr46675.c	(revision 0)
@@ -0,0 +1,29 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern void abort (void);
+
+int j;
+
+void
+__attribute__((noinline))
+foo (int n)
+{
+  int npairs, i;
+  npairs = n - (-__INT_MAX__ - 1);
+
+  if (npairs > 0)
+    for (i = 0; i < npairs; i++)
+      j++;
+}
+
+int
+main ()
+{
+  foo (5 - __INT_MAX__ - 1);
+
+  if (j != 5)
+    abort ();
+
+  return 0;
+}