]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/48189 (ICE: SIGFPE (division by zero) in in predict_loops...
authorJakub Jelinek <jakub@gcc.gnu.org>
Wed, 9 Jan 2013 09:00:22 +0000 (10:00 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 9 Jan 2013 09:00:22 +0000 (10:00 +0100)
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.

* gcc.dg/pr48189.c: New test.

From-SVN: r195046

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

index b29c10b31b4dc5d5e4f91bee816e39a535f8831e..1d37b78a9e3363cfbae4d180eacc3a713f9faffa 100644 (file)
@@ -1,3 +1,10 @@
+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-01-08  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        * config/pa/pa.h (VAL_U6_BITS_P): Define.
index 0c16b537c4be911524c91b868b10f66ed42496be..67a5f74ec6cbba8ceacb2571c95accc8859ba56e 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,
-   2011, 2012 Free Software Foundation, Inc.
+   2011, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -1434,7 +1434,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;
@@ -1456,6 +1457,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 f22287404f953bb59de668284cff0e731c757b5f..22e5f53930816d97db205d4961617ad21e01f8d4 100644 (file)
@@ -1,3 +1,8 @@
+2013-01-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/48189
+       * gcc.dg/pr48189.c: New test.
+
 2013-01-04  Jan Hubicka  <jh@suse.cz>
 
        PR tree-optimization/55823
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];
+}