]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/48189 (ICE: SIGFPE (division by zero) in in predict...
authorMarek Polacek <polacek@redhat.com>
Thu, 4 Apr 2013 11:03:11 +0000 (11:03 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 4 Apr 2013 11:03:11 +0000 (11:03 +0000)
        Backported from mainline
        2013-01-09  Steven Bosscher  <steven@gcc.gnu.org>
                    Jakub Jelinek  <jakub@redhat.com>

        PR tree-optimization/48189
        * predict.c (predict_loops): If max is 0, don't call compare_tree_int.
        If nitercst is 0, don't predict the exit edge.

From-SVN: r197478

gcc/ChangeLog
gcc/predict.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr48189.c [new file with mode: 0644]

index f5ddc786f7cf64de02be031b7b4e0f416c02ef91..f9b7ec9c8b583b591c6164da3e23977d539aadb3 100644 (file)
@@ -1,3 +1,13 @@
+2013-04-04  Marek Polacek  <polacek@redhat.com>
+
+       Backported from mainline
+       2013-01-09  Steven Bosscher  <steven@gcc.gnu.org>
+                   Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/48189
+       * predict.c (predict_loops): If max is 0, don't call compare_tree_int.
+       If nitercst is 0, don't predict the exit edge.
+
 2013-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index f00424c3b1c00377d240e77397addc59c5e8a645..18fda083da33ee0fd4039c10e41656dbd8f76f83 100644 (file)
@@ -1,6 +1,6 @@
 /* Branch prediction routines for the GNU compiler.
    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
-   Free Software Foundation, Inc.
+   2011, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -966,7 +966,8 @@ predict_loops (void)
          if (TREE_CODE (niter) == INTEGER_CST)
            {
              if (host_integerp (niter, 1)
-                 && compare_tree_int (niter, max-1) == -1)
+                 && max
+                 && compare_tree_int (niter, max - 1) == -1)
                nitercst = tree_low_cst (niter, 1) + 1;
              else
                nitercst = max;
@@ -988,6 +989,11 @@ predict_loops (void)
          else
            continue;
 
+         /* If the prediction for number of iterations is zero, do not
+            predict the exit edges.  */
+         if (nitercst == 0)
+           continue;
+
          probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst);
          predict_edge (ex, predictor, probability);
        }
index cd660f6e3fa02485899fa240149fc371fa27f0d6..80016c5622ff999bdca9378f36b9cb40cb314d3a 100644 (file)
@@ -1,3 +1,11 @@
+2013-04-04  Marek Polacek  <polacek@redhat.com>
+
+       Backported from mainline
+       2013-01-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/48189
+       * gcc.dg/pr48189.c: New test.
+
 2013-04-04  Tobias Burnus  <burnus@net-b.de>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gcc.dg/pr48189.c b/gcc/testsuite/gcc.dg/pr48189.c
new file mode 100644 (file)
index 0000000..86b995d
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR tree-optimization/48189 */
+/* { dg-do compile } */
+/* { dg-options "-O --param max-predicted-iterations=0" } */
+
+struct S { int s[8]; };
+  
+void
+foo (int *x, struct S *y)
+{
+  int i;
+  for (i = 0; y[i].s[i]; i++)
+    *x++ = y[i].s[i];
+}