Patchwork Backport PR48189 fix

login
register
mail settings
Submitter Marek Polacek
Date April 16, 2013, 7:05 a.m.
Message ID <20130416070533.GD13346@redhat.com>
Download mbox | patch
Permalink /patch/236841/
State New
Headers show

Comments

Marek Polacek - April 16, 2013, 7:05 a.m.
I'd like to backport the fox for PR48189 to 4.7 branch, so we can
close the PR.  Ok?

2013-04-16  Marek Polacek  <polacek@redhat.com>

	Backport from mainline
	2013-01-08  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.

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


	Marek
Jakub Jelinek - April 16, 2013, 7:16 a.m.
On Tue, Apr 16, 2013 at 09:05:33AM +0200, Marek Polacek wrote:
> I'd like to backport the fox for PR48189 to 4.7 branch, so we can
> close the PR.  Ok?

Ok, thanks.

	Jakub

Patch

--- gcc/predict.c.mp	2013-04-16 08:57:31.922977475 +0200
+++ gcc/predict.c	2013-04-16 08:57:34.978987175 +0200
@@ -983,7 +983,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;
@@ -1005,6 +1006,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);
 	}
--- gcc/testsuite/gcc.dg/pr48189.c.mp	2013-04-16 09:00:08.141473343 +0200
+++ gcc/testsuite/gcc.dg/pr48189.c	2013-04-16 08:59:59.443445251 +0200
@@ -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];
+}