Patchwork [google] revert r185948

login
register
mail settings
Submitter Dehao Chen
Date April 4, 2012, 12:30 a.m.
Message ID <CAO2gOZW9OiCw3vZPOcOmJwsPU+CX73MndEso44+w5RC6JuBNPA@mail.gmail.com>
Download mbox | patch
Permalink /patch/150571/
State New
Headers show

Comments

Dehao Chen - April 4, 2012, 12:30 a.m.
Revert r185948, which causes regression to major applications.

Bootstrapped.

OK for google-4_6?

Thanks,
Dehao
Rong Xu - April 4, 2012, 12:42 a.m.
OK for google-4_6 branch.

-Rong

On Tue, Apr 3, 2012 at 5:30 PM, Dehao Chen <dehao@google.com> wrote:
>
> Revert r185948, which causes regression to major applications.
>
> Bootstrapped.
>
> OK for google-4_6?
>
> Thanks,
> Dehao
>
> Index: gcc/testsuite/gcc.dg/predict-3.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/predict-3.c    (revision 186128)
> +++ gcc/testsuite/gcc.dg/predict-3.c    (working copy)
> @@ -10,16 +10,10 @@
>   int i, ret = 0;
>   for (i = 0; i <= bound; i++)
>     {
> -      if (i < bound - 2)
> -       global += bar (i);
> -      if (i <= bound)
> -       global += bar (i);
> -      if (i + 1 < bound)
> -       global += bar (i);
>       if (i != bound)
>        global += bar (i);
>     }
>  }
>
> -/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
> 100.0%" 4 "profile_estimate"} } */
> +/* { dg-final { scan-tree-dump "loop iv compare heuristics"
> "profile_estimate"} } */
>  /* { dg-final { cleanup-tree-dump "profile_estimate" } } */
> Index: gcc/testsuite/gcc.dg/predict-4.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/predict-4.c    (revision 186128)
> +++ gcc/testsuite/gcc.dg/predict-4.c    (working copy)
> @@ -15,5 +15,5 @@
>     }
>  }
>
> -/* { dg-final { scan-tree-dump "loop iv compare heuristics: 50.0%"
> "profile_estimate"} } */
> +/* { dg-final { scan-tree-dump "loop iv compare heuristics"
> "profile_estimate"} } */
>  /* { dg-final { cleanup-tree-dump "profile_estimate" } } */
> Index: gcc/testsuite/gcc.dg/predict-1.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/predict-1.c    (revision 186128)
> +++ gcc/testsuite/gcc.dg/predict-1.c    (working copy)
> @@ -10,18 +10,10 @@
>   int i, ret = 0;
>   for (i = 0; i < bound; i++)
>     {
> -      if (i > bound)
> -       global += bar (i);
> -      if (i >= bound + 2)
> -       global += bar (i);
>       if (i > bound - 2)
>        global += bar (i);
> -      if (i + 2 > bound)
> -       global += bar (i);
> -      if (i == 10)
> -       global += bar (i);
>     }
>  }
>
> -/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
> 0.0%" 5 "profile_estimate"} } */
> +/* { dg-final { scan-tree-dump "loop iv compare heuristics"
> "profile_estimate"} } */
>  /* { dg-final { cleanup-tree-dump "profile_estimate" } } */
> Index: gcc/testsuite/gcc.dg/predict-5.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/predict-5.c    (revision 186128)
> +++ gcc/testsuite/gcc.dg/predict-5.c    (working copy)
> @@ -1,25 +0,0 @@
> -/* { dg-do compile } */
> -/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
> -
> -extern int global;
> -
> -int bar (int);
> -
> -void foo (int base, int bound)
> -{
> -  int i, ret = 0;
> -  for (i = base; i <= bound; i++)
> -    {
> -      if (i > base)
> -       global += bar (i);
> -      if (i > base + 1)
> -       global += bar (i);
> -      if (i >= base + 3)
> -       global += bar (i);
> -      if (i - 2 >= base)
> -       global += bar (i);
> -    }
> -}
> -
> -/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
> 100.0%" 4 "profile_estimate"} } */
> -/* { dg-final { cleanup-tree-dump "profile_estimate" } } */
> Index: gcc/testsuite/gcc.dg/predict-2.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/predict-2.c    (revision 186128)
> +++ gcc/testsuite/gcc.dg/predict-2.c    (working copy)
> @@ -5,20 +5,12 @@
>
>  int bar(int);
>
> -void foo (int base, int bound)
> +void foo (int bound)
>  {
>   int i, ret = 0;
> -  for (i = base; i < bound; i++)
> +  for (i = 0; i < bound; i++)
>     {
> -      if (i > bound * bound)
> -       global += bar (i);
> -      if (i > bound + 10)
> -       global += bar (i);
> -      if (i <= bound + 10)
> -       global += bar (i);
> -      if (i > base + 10)
> -       global += bar (i);
> -      if (i < base - 10)
> +      if (i > bound * bound )
>        global += bar (i);
>     }
>  }
> Index: gcc/testsuite/gcc.dg/predict-6.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/predict-6.c    (revision 186128)
> +++ gcc/testsuite/gcc.dg/predict-6.c    (working copy)
> @@ -1,25 +0,0 @@
> -/* { dg-do compile } */
> -/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
> -
> -extern int global;
> -
> -int bar (int);
> -
> -void foo (int base, int bound)
> -{
> -  int i, ret = 0;
> -  for (i = base; i <= bound; i++)
> -    {
> -      if (i < base)
> -       global += bar (i);
> -      if (i < base + 1)
> -       global += bar (i);
> -      if (i <= base + 3)
> -       global += bar (i);
> -      if (i - 1 < base)
> -       global += bar (i);
> -    }
> -}
> -
> -/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
> 0.0%" 4 "profile_estimate"} } */
> -/* { dg-final { cleanup-tree-dump "profile_estimate" } } */
> Index: gcc/predict.c
> ===================================================================
> --- gcc/predict.c       (revision 186128)
> +++ gcc/predict.c       (working copy)
> @@ -1070,10 +1070,6 @@
>     bound = get_base_value (bound);
>   if (!bound)
>     return false;
> -  if (TREE_CODE (base) != INTEGER_CST)
> -    base = get_base_value (base);
> -  if (!base)
> -    return false;
>
>   *loop_invariant = bound;
>   *compare_code = code;
> @@ -1189,7 +1185,8 @@
>       return;
>     }
>
> -  if (!expr_coherent_p(loop_iv_base_var, compare_base))
> +  if (!expr_coherent_p (loop_bound_var, compare_var)
> +      || loop_iv_base_var != compare_base)
>     return;
>
>   /* If loop bound, base and compare bound are all constents, we can
> @@ -1233,52 +1230,34 @@
>       return;
>     }
>
> -  if (expr_coherent_p (loop_bound_var, compare_var))
> -    {
> -      if ((loop_bound_code == LT_EXPR || loop_bound_code == LE_EXPR)
> -         && (compare_code == LT_EXPR || compare_code == LE_EXPR))
> -       predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
> -      else if ((loop_bound_code == GT_EXPR || loop_bound_code == GE_EXPR)
> -              && (compare_code == GT_EXPR || compare_code == GE_EXPR))
> -       predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
> -      else if (loop_bound_code == NE_EXPR)
> -       {
> -         /* If the loop backedge condition is "(i != bound)", we do
> -            the comparison based on the step of IV:
> -            * step < 0 : backedge condition is like (i > bound)
> -            * step > 0 : backedge condition is like (i < bound)  */
> -         gcc_assert (loop_bound_step != 0);
> -         if (loop_bound_step > 0
> -             && (compare_code == LT_EXPR
> -                 || compare_code == LE_EXPR))
> -           predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
> -         else if (loop_bound_step < 0
> -                  && (compare_code == GT_EXPR
> -                      || compare_code == GE_EXPR))
> -           predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
> -         else
> -           predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
> -       }
> -      else
> -       /* The branch is predicted not-taken if loop_bound_code is
> -          opposite with compare_code.  */
> -       predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
> -    }
> -  else if (expr_coherent_p (loop_iv_base_var, compare_var))
> -    {
> -      /* For cases like:
> -          for (i = s; i < h; i++)
> -            if (i > s + 2) ....
> -        The branch should be predicted taken.  */
> +  if ((loop_bound_code == LT_EXPR || loop_bound_code == LE_EXPR)
> +      && (compare_code == LT_EXPR || compare_code == LE_EXPR))
> +    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
> +  else if ((loop_bound_code == GT_EXPR || loop_bound_code == GE_EXPR)
> +          && (compare_code == GT_EXPR || compare_code == GE_EXPR))
> +    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
> +  else if (loop_bound_code == NE_EXPR)
> +    {
> +      /* If the loop backedge condition is "(i != bound)", we do
> +        the comparison based on the step of IV:
> +          * step < 0 : backedge condition is like (i > bound)
> +          * step > 0 : backedge condition is like (i < bound)  */
> +      gcc_assert (loop_bound_step != 0);
>       if (loop_bound_step > 0
> -         && (compare_code == GT_EXPR || compare_code == GE_EXPR))
> +         && (compare_code == LT_EXPR
> +             || compare_code == LE_EXPR))
>        predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
>       else if (loop_bound_step < 0
> -              && (compare_code == LT_EXPR || compare_code == LE_EXPR))
> +              && (compare_code == GT_EXPR
> +                  || compare_code == GE_EXPR))
>        predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
>       else
>        predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
>     }
> +  else
> +    /* The branch is predicted not-taken if loop_bound_code is
> +       opposite with compare_code.  */
> +    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
>  }
>
>  /* Predict edge probabilities by exploiting loop structure.  */

Patch

Index: gcc/testsuite/gcc.dg/predict-3.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-3.c	(revision 186128)
+++ gcc/testsuite/gcc.dg/predict-3.c	(working copy)
@@ -10,16 +10,10 @@ 
   int i, ret = 0;
   for (i = 0; i <= bound; i++)
     {
-      if (i < bound - 2)
-	global += bar (i);
-      if (i <= bound)
-	global += bar (i);
-      if (i + 1 < bound)
-	global += bar (i);
       if (i != bound)
 	global += bar (i);
     }
 }

-/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
100.0%" 4 "profile_estimate"} } */
+/* { dg-final { scan-tree-dump "loop iv compare heuristics"
"profile_estimate"} } */
 /* { dg-final { cleanup-tree-dump "profile_estimate" } } */
Index: gcc/testsuite/gcc.dg/predict-4.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-4.c	(revision 186128)
+++ gcc/testsuite/gcc.dg/predict-4.c	(working copy)
@@ -15,5 +15,5 @@ 
     }
 }

-/* { dg-final { scan-tree-dump "loop iv compare heuristics: 50.0%"
"profile_estimate"} } */
+/* { dg-final { scan-tree-dump "loop iv compare heuristics"
"profile_estimate"} } */
 /* { dg-final { cleanup-tree-dump "profile_estimate" } } */
Index: gcc/testsuite/gcc.dg/predict-1.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-1.c	(revision 186128)
+++ gcc/testsuite/gcc.dg/predict-1.c	(working copy)
@@ -10,18 +10,10 @@ 
   int i, ret = 0;
   for (i = 0; i < bound; i++)
     {
-      if (i > bound)
-	global += bar (i);
-      if (i >= bound + 2)
-	global += bar (i);
       if (i > bound - 2)
 	global += bar (i);
-      if (i + 2 > bound)
-	global += bar (i);
-      if (i == 10)
-	global += bar (i);
     }
 }

-/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
0.0%" 5 "profile_estimate"} } */
+/* { dg-final { scan-tree-dump "loop iv compare heuristics"
"profile_estimate"} } */
 /* { dg-final { cleanup-tree-dump "profile_estimate" } } */
Index: gcc/testsuite/gcc.dg/predict-5.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-5.c	(revision 186128)
+++ gcc/testsuite/gcc.dg/predict-5.c	(working copy)
@@ -1,25 +0,0 @@ 
-/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
-
-extern int global;
-
-int bar (int);
-
-void foo (int base, int bound)
-{
-  int i, ret = 0;
-  for (i = base; i <= bound; i++)
-    {
-      if (i > base)
-	global += bar (i);
-      if (i > base + 1)
-	global += bar (i);
-      if (i >= base + 3)
-	global += bar (i);
-      if (i - 2 >= base)
-	global += bar (i);
-    }
-}
-
-/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
100.0%" 4 "profile_estimate"} } */
-/* { dg-final { cleanup-tree-dump "profile_estimate" } } */
Index: gcc/testsuite/gcc.dg/predict-2.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-2.c	(revision 186128)
+++ gcc/testsuite/gcc.dg/predict-2.c	(working copy)
@@ -5,20 +5,12 @@ 

 int bar(int);

-void foo (int base, int bound)
+void foo (int bound)
 {
   int i, ret = 0;
-  for (i = base; i < bound; i++)
+  for (i = 0; i < bound; i++)
     {
-      if (i > bound * bound)
-	global += bar (i);
-      if (i > bound + 10)
-	global += bar (i);
-      if (i <= bound + 10)
-	global += bar (i);
-      if (i > base + 10)
-	global += bar (i);
-      if (i < base - 10)
+      if (i > bound * bound )
 	global += bar (i);
     }
 }
Index: gcc/testsuite/gcc.dg/predict-6.c
===================================================================
--- gcc/testsuite/gcc.dg/predict-6.c	(revision 186128)
+++ gcc/testsuite/gcc.dg/predict-6.c	(working copy)
@@ -1,25 +0,0 @@ 
-/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
-
-extern int global;
-
-int bar (int);
-
-void foo (int base, int bound)
-{
-  int i, ret = 0;
-  for (i = base; i <= bound; i++)
-    {
-      if (i < base)
-	global += bar (i);
-      if (i < base + 1)
-	global += bar (i);
-      if (i <= base + 3)
-	global += bar (i);
-      if (i - 1 < base)
-	global += bar (i);
-    }
-}
-
-/* { dg-final { scan-tree-dump-times "loop iv compare heuristics:
0.0%" 4 "profile_estimate"} } */
-/* { dg-final { cleanup-tree-dump "profile_estimate" } } */
Index: gcc/predict.c
===================================================================
--- gcc/predict.c	(revision 186128)
+++ gcc/predict.c	(working copy)
@@ -1070,10 +1070,6 @@ 
     bound = get_base_value (bound);
   if (!bound)
     return false;
-  if (TREE_CODE (base) != INTEGER_CST)
-    base = get_base_value (base);
-  if (!base)
-    return false;

   *loop_invariant = bound;
   *compare_code = code;
@@ -1189,7 +1185,8 @@ 
       return;
     }

-  if (!expr_coherent_p(loop_iv_base_var, compare_base))
+  if (!expr_coherent_p (loop_bound_var, compare_var)
+      || loop_iv_base_var != compare_base)
     return;

   /* If loop bound, base and compare bound are all constents, we can
@@ -1233,52 +1230,34 @@ 
       return;
     }

-  if (expr_coherent_p (loop_bound_var, compare_var))
-    {
-      if ((loop_bound_code == LT_EXPR || loop_bound_code == LE_EXPR)
-	  && (compare_code == LT_EXPR || compare_code == LE_EXPR))
-	predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
-      else if ((loop_bound_code == GT_EXPR || loop_bound_code == GE_EXPR)
-	       && (compare_code == GT_EXPR || compare_code == GE_EXPR))
-	predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
-      else if (loop_bound_code == NE_EXPR)
-	{
-	  /* If the loop backedge condition is "(i != bound)", we do
-	     the comparison based on the step of IV:
-	     * step < 0 : backedge condition is like (i > bound)
-	     * step > 0 : backedge condition is like (i < bound)  */
-	  gcc_assert (loop_bound_step != 0);
-	  if (loop_bound_step > 0
-	      && (compare_code == LT_EXPR
-		  || compare_code == LE_EXPR))
-	    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
-	  else if (loop_bound_step < 0
-		   && (compare_code == GT_EXPR
-		       || compare_code == GE_EXPR))
-	    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
-	  else
-	    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
-	}
-      else
-	/* The branch is predicted not-taken if loop_bound_code is
-	   opposite with compare_code.  */
-	predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
-    }
-  else if (expr_coherent_p (loop_iv_base_var, compare_var))
-    {
-      /* For cases like:
-	   for (i = s; i < h; i++)
-	     if (i > s + 2) ....
-	 The branch should be predicted taken.  */
+  if ((loop_bound_code == LT_EXPR || loop_bound_code == LE_EXPR)
+      && (compare_code == LT_EXPR || compare_code == LE_EXPR))
+    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
+  else if ((loop_bound_code == GT_EXPR || loop_bound_code == GE_EXPR)
+	   && (compare_code == GT_EXPR || compare_code == GE_EXPR))
+    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
+  else if (loop_bound_code == NE_EXPR)
+    {
+      /* If the loop backedge condition is "(i != bound)", we do
+	 the comparison based on the step of IV:
+	   * step < 0 : backedge condition is like (i > bound)
+	   * step > 0 : backedge condition is like (i < bound)  */
+      gcc_assert (loop_bound_step != 0);
       if (loop_bound_step > 0
-	  && (compare_code == GT_EXPR || compare_code == GE_EXPR))
+	  && (compare_code == LT_EXPR
+	      || compare_code == LE_EXPR))
 	predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
       else if (loop_bound_step < 0
-	       && (compare_code == LT_EXPR || compare_code == LE_EXPR))
+	       && (compare_code == GT_EXPR
+		   || compare_code == GE_EXPR))
 	predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, TAKEN);
       else
 	predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
     }
+  else
+    /* The branch is predicted not-taken if loop_bound_code is
+       opposite with compare_code.  */
+    predict_edge_def (then_edge, PRED_LOOP_IV_COMPARE, NOT_TAKEN);
 }

 /* Predict edge probabilities by exploiting loop structure.  */