Re: patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-05-09 Thread Jakub Jelinek
On Wed, May 09, 2012 at 09:02:14AM +0800, Dehao Chen wrote:
 Sorry for the error. Here is a new patch to fix them:
 
 gcc/testsuite/ChangeLog:
 2012-05-08  Dehao Chen  de...@google.com
 
   * gcc.dg/predict-1.c: Remove the replicated text in this text.
   * gcc.dg/predict-2.c: Likewise.
   * gcc.dg/predict-3.c: Likewise.
   * gcc.dg/predict-4.c: Likewise.
   * gcc.dg/predict-5.c: Likewise.
   * gcc.dg/predict-6.c: Likewise.

Ok (you could have committed it as obvious even).

 --- gcc/ChangeLog (revision 187307)
 +++ gcc/ChangeLog (working copy)
 @@ -110,15 +110,15 @@
 
  2012-05-08  Dehao Chen  de...@google.com
 
 - * predict.c (find_qualified_ssa_name): New
 - (find_ssa_name_in_expr): New
 - (find_ssa_name_in_assign_stmt): New
 - (is_comparison_with_loop_invariant_p): New
 - (is_bound_expr_similar): New
 - (predict_iv_comparison): New
 + * predict.c (find_qualified_ssa_name): New.
 + (find_ssa_name_in_expr): New.
 + (find_ssa_name_in_assign_stmt): New.
 + (is_comparison_with_loop_invariant_p): New.
 + (is_bound_expr_similar): New.
 + (predict_iv_comparison): New.
   (predict_loops): Add heuristic for loop-nested branches that compare an
   induction variable to a loop bound variable.
 - * predict.def (PRED_LOOP_IV_COMPARE): New macro
 + * predict.def (PRED_LOOP_IV_COMPARE): New macro.
 
  2012-05-08  Uros Bizjak  ubiz...@gmail.com
 
 Index: gcc/testsuite/gcc.dg/predict-3.c
 ===
 --- gcc/testsuite/gcc.dg/predict-3.c  (revision 187307)
 +++ gcc/testsuite/gcc.dg/predict-3.c  (working copy)
 @@ -23,28 +23,3 @@
 
  /* { dg-final { scan-tree-dump-times loop iv compare heuristics:
 100.0% 4 profile_estimate} } */
  /* { dg-final { cleanup-tree-dump profile_estimate } } */
 -/* { dg-do compile } */
 -/* { dg-options -O2 -fdump-tree-profile_estimate } */
 -
 -extern int global;
 -
 -int bar(int);
 -
 -void foo (int bound)
 -{
 -  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 { cleanup-tree-dump profile_estimate } } */
 Index: gcc/testsuite/gcc.dg/predict-4.c
 ===
 --- gcc/testsuite/gcc.dg/predict-4.c  (revision 187307)
 +++ gcc/testsuite/gcc.dg/predict-4.c  (working copy)
 @@ -17,22 +17,3 @@
 
  /* { dg-final { scan-tree-dump loop iv compare heuristics: 50.0%
 profile_estimate} } */
  /* { dg-final { cleanup-tree-dump profile_estimate } } */
 -/* { dg-do compile } */
 -/* { dg-options -O2 -fdump-tree-profile_estimate } */
 -
 -extern int global;
 -
 -int bar(int);
 -
 -void foo (int bound)
 -{
 -  int i, ret = 0;
 -  for (i = 0; i  10; i++)
 -{
 -  if (i  5)
 - global += bar (i);
 -}
 -}
 -
 -/* { dg-final { scan-tree-dump loop iv compare heuristics: 50.0%
 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 187307)
 +++ gcc/testsuite/gcc.dg/predict-1.c  (working copy)
 @@ -25,30 +25,3 @@
 
  /* { dg-final { scan-tree-dump-times loop iv compare heuristics:
 0.0% 5 profile_estimate} } */
  /* { dg-final { cleanup-tree-dump profile_estimate } } */
 -/* { dg-do compile } */
 -/* { dg-options -O2 -fdump-tree-profile_estimate } */
 -
 -extern int global;
 -
 -int bar(int);
 -
 -void foo (int bound)
 -{
 -  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 { cleanup-tree-dump profile_estimate } } */
 Index: gcc/testsuite/gcc.dg/predict-5.c
 ===
 --- gcc/testsuite/gcc.dg/predict-5.c  (revision 187307)
 +++ gcc/testsuite/gcc.dg/predict-5.c  (working copy)
 @@ -23,28 +23,3 @@
 
  /* { dg-final { scan-tree-dump-times loop iv compare heuristics:
 100.0% 4 profile_estimate} } */
  /* { dg-final { cleanup-tree-dump profile_estimate } } */
 -/* { 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  

Re: patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-05-08 Thread Jakub Jelinek
On Fri, May 04, 2012 at 09:46:22PM +0800, Dehao Chen wrote:
 Thanks for the prompt response. Attached is the updated patch.
 
 Passed bootstrap and all regression tests.

All the new testcases fail for me, on both x86_64-linux and i686-linux,
apparently because of incorrectly committed patch (each testcase source
contains the test twice).

Also, the ChangeLog entries are missing dot at end of each change
description (New instead of New. etc.).

 Index: gcc/testsuite/gcc.dg/predict-3.c
 ===
 --- gcc/testsuite/gcc.dg/predict-3.c  (revision 0)
 +++ gcc/testsuite/gcc.dg/predict-3.c  (revision 0)
 @@ -0,0 +1,25 @@
 +/* { dg-do compile } */
 +/* { dg-options -O2 -fdump-tree-profile_estimate } */
 +
 +extern int global;
 +
 +int bar(int);
 +
 +void foo (int bound)
 +{
 +  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 { cleanup-tree-dump profile_estimate } } */

Jakub


Re: patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-05-08 Thread Dehao Chen
Sorry for the error. Here is a new patch to fix them:

gcc/testsuite/ChangeLog:
2012-05-08  Dehao Chen  de...@google.com

* gcc.dg/predict-1.c: Remove the replicated text in this text.
* gcc.dg/predict-2.c: Likewise.
* gcc.dg/predict-3.c: Likewise.
* gcc.dg/predict-4.c: Likewise.
* gcc.dg/predict-5.c: Likewise.
* gcc.dg/predict-6.c: Likewise.

Index: gcc/ChangeLog
===
--- gcc/ChangeLog   (revision 187307)
+++ gcc/ChangeLog   (working copy)
@@ -110,15 +110,15 @@

 2012-05-08  Dehao Chen  de...@google.com

-   * predict.c (find_qualified_ssa_name): New
-   (find_ssa_name_in_expr): New
-   (find_ssa_name_in_assign_stmt): New
-   (is_comparison_with_loop_invariant_p): New
-   (is_bound_expr_similar): New
-   (predict_iv_comparison): New
+   * predict.c (find_qualified_ssa_name): New.
+   (find_ssa_name_in_expr): New.
+   (find_ssa_name_in_assign_stmt): New.
+   (is_comparison_with_loop_invariant_p): New.
+   (is_bound_expr_similar): New.
+   (predict_iv_comparison): New.
(predict_loops): Add heuristic for loop-nested branches that compare an
induction variable to a loop bound variable.
-   * predict.def (PRED_LOOP_IV_COMPARE): New macro
+   * predict.def (PRED_LOOP_IV_COMPARE): New macro.

 2012-05-08  Uros Bizjak  ubiz...@gmail.com

Index: gcc/testsuite/gcc.dg/predict-3.c
===
--- gcc/testsuite/gcc.dg/predict-3.c(revision 187307)
+++ gcc/testsuite/gcc.dg/predict-3.c(working copy)
@@ -23,28 +23,3 @@

 /* { dg-final { scan-tree-dump-times loop iv compare heuristics:
100.0% 4 profile_estimate} } */
 /* { dg-final { cleanup-tree-dump profile_estimate } } */
-/* { dg-do compile } */
-/* { dg-options -O2 -fdump-tree-profile_estimate } */
-
-extern int global;
-
-int bar(int);
-
-void foo (int bound)
-{
-  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 { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-4.c
===
--- gcc/testsuite/gcc.dg/predict-4.c(revision 187307)
+++ gcc/testsuite/gcc.dg/predict-4.c(working copy)
@@ -17,22 +17,3 @@

 /* { dg-final { scan-tree-dump loop iv compare heuristics: 50.0%
profile_estimate} } */
 /* { dg-final { cleanup-tree-dump profile_estimate } } */
-/* { dg-do compile } */
-/* { dg-options -O2 -fdump-tree-profile_estimate } */
-
-extern int global;
-
-int bar(int);
-
-void foo (int bound)
-{
-  int i, ret = 0;
-  for (i = 0; i  10; i++)
-{
-  if (i  5)
-   global += bar (i);
-}
-}
-
-/* { dg-final { scan-tree-dump loop iv compare heuristics: 50.0%
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 187307)
+++ gcc/testsuite/gcc.dg/predict-1.c(working copy)
@@ -25,30 +25,3 @@

 /* { dg-final { scan-tree-dump-times loop iv compare heuristics:
0.0% 5 profile_estimate} } */
 /* { dg-final { cleanup-tree-dump profile_estimate } } */
-/* { dg-do compile } */
-/* { dg-options -O2 -fdump-tree-profile_estimate } */
-
-extern int global;
-
-int bar(int);
-
-void foo (int bound)
-{
-  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 { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-5.c
===
--- gcc/testsuite/gcc.dg/predict-5.c(revision 187307)
+++ gcc/testsuite/gcc.dg/predict-5.c(working copy)
@@ -23,28 +23,3 @@

 /* { dg-final { scan-tree-dump-times loop iv compare heuristics:
100.0% 4 profile_estimate} } */
 /* { dg-final { cleanup-tree-dump profile_estimate } } */
-/* { 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 

Re: patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-05-04 Thread Jan Hubicka
 gcc/ChangeLog
 2012-05-04  Dehao Chen  de...@google.com
 
   * predict.c (find_qualified_ssa_name): New
   (find_ssa_name_in_expr): New
   (find_ssa_name_in_assign_stmt): New
   (is_comparison_with_loop_invariant_p): New
   (is_bound_expr_similar): New
   (predict_iv_comparison): New
   (predict_loops): Add heuristic for loop-nested branches that compare an
   induction variable to a loop bound variable.
   * predict.def (PRED_LOOP_IV_COMPARE): New macro
 
 gcc/testsuite/ChangeLog
 2012-05-04  Dehao Chen  de...@google.com
 
   * gcc.dg/predict-1.c: Check if LOOP_IV_COMPARE static predict
   heuristic is working properly.
   * gcc.dg/predict-2.c: Likewise.
   * gcc/dg/predict-3.c: Likewise.
   * gcc/dg/predict-4.c: Likewise.
   * gcc/dg/predict-5.c: Likewise.
   * gcc/dg/predict-6.c: Likewise.
 
 Index: gcc/predict.c
 ===
 --- gcc/predict.c (revision 187140)
 +++ gcc/predict.c (working copy)
 @@ -946,6 +946,358 @@
  }
  }
 
 +/* Check if T1 and T2 satisfy the IV_COMPARE condition.
 +   Return the SSA_NAME if the condition satisfies, NULL otherwise.
 +
 +   T1 and T2 should be one of the following cases:
 + 1. T1 is SSA_NAME, T2 is NULL
 + 2. T1 is SSA_NAME, T2 is INTEGER_CST between [-4, 4]
 + 3. T2 is SSA_NAME, T1 is INTEGER_CST between [-4, 4]  */
 +
 +static tree
 +strips_small_constant (tree t1, tree t2)
 +{
 +  tree ret = NULL;
 +  int value = 0;
 +
 +  if (!t1)
 +return NULL;
 +  else if (TREE_CODE (t1) == SSA_NAME)
 +ret = t1;
 +  else if (TREE_CODE (t1) == INTEGER_CST  host_integerp (t1, 0))

host_integer_p will check TREE_CODE (t1) == INTEGER_CST for you.
 +  /* If loop bound, base and compare bound are all constents, we can
constants.
 + calculate the probability directly.  */
 +  if (TREE_CODE (loop_bound_var) == INTEGER_CST
 +   TREE_CODE (compare_var) == INTEGER_CST
 +   TREE_CODE (compare_base) == INTEGER_CST
 +   host_integerp (loop_bound_var, 0)
 +   host_integerp (compare_var, 0)
 +   host_integerp (compare_base, 0))
Again host_integerp will test that for you.

 + probability = (double) REG_BR_PROB_BASE * compare_count / loop_count;
 +  predict_edge (then_edge, PRED_LOOP_IV_COMPARE, probability);
 +  return;
 +}
 +
 +  if (expr_coherent_p (loop_bound_var, compare_var))

You probably want to thave two predictor, one when the probability is known
declared as first match predictor with high probability and one when probability
is unknown combined the usual way...

Otherwise the patch seems good to me.

Honza


Re: patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-05-04 Thread Dehao Chen
Hi, Honza,

Thanks for the prompt response. Attached is the updated patch.

Passed bootstrap and all regression tests.

Thanks,
Dehao

Index: gcc/testsuite/gcc.dg/predict-3.c
===
--- gcc/testsuite/gcc.dg/predict-3.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-3.c(revision 0)
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options -O2 -fdump-tree-profile_estimate } */
+
+extern int global;
+
+int bar(int);
+
+void foo (int bound)
+{
+  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 { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-4.c
===
--- gcc/testsuite/gcc.dg/predict-4.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-4.c(revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options -O2 -fdump-tree-profile_estimate } */
+
+extern int global;
+
+int bar(int);
+
+void foo (int bound)
+{
+  int i, ret = 0;
+  for (i = 0; i  10; i++)
+{
+  if (i  5)
+   global += bar (i);
+}
+}
+
+/* { dg-final { scan-tree-dump loop iv compare heuristics: 50.0%
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 0)
+++ gcc/testsuite/gcc.dg/predict-1.c(revision 0)
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options -O2 -fdump-tree-profile_estimate } */
+
+extern int global;
+
+int bar(int);
+
+void foo (int bound)
+{
+  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 { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-5.c
===
--- gcc/testsuite/gcc.dg/predict-5.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-5.c(revision 0)
@@ -0,0 +1,25 @@
+/* { 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 0)
+++ gcc/testsuite/gcc.dg/predict-2.c(revision 0)
@@ -0,0 +1,27 @@
+/* { 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  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)
+   global += bar (i);
+}
+}
+
+/* { dg-final { scan-tree-dump-not loop iv compare heuristics
profile_estimate} } */
+/* { dg-final { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-6.c
===
--- gcc/testsuite/gcc.dg/predict-6.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-6.c(revision 0)
@@ -0,0 +1,25 @@
+/* { 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

patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-05-03 Thread Dehao Chen
http://gcc.gnu.org/ml/gcc-patches/2012-01/msg00377.html

I've also refined the patch, adding support for comparison of IV to
its initial value.

The updated patch is attached, and you can also it in:
http://codereview.appspot.com/5504086/

Passed bootstrap and all gcc regression tests.

Thanks,
Dehao

gcc/ChangeLog
2012-05-04  Dehao Chen  de...@google.com

* predict.c (find_qualified_ssa_name): New
(find_ssa_name_in_expr): New
(find_ssa_name_in_assign_stmt): New
(is_comparison_with_loop_invariant_p): New
(is_bound_expr_similar): New
(predict_iv_comparison): New
(predict_loops): Add heuristic for loop-nested branches that compare an
induction variable to a loop bound variable.
* predict.def (PRED_LOOP_IV_COMPARE): New macro

gcc/testsuite/ChangeLog
2012-05-04  Dehao Chen  de...@google.com

* gcc.dg/predict-1.c: Check if LOOP_IV_COMPARE static predict
heuristic is working properly.
* gcc.dg/predict-2.c: Likewise.
* gcc/dg/predict-3.c: Likewise.
* gcc/dg/predict-4.c: Likewise.
* gcc/dg/predict-5.c: Likewise.
* gcc/dg/predict-6.c: Likewise.

Index: gcc/testsuite/gcc.dg/predict-3.c
===
--- gcc/testsuite/gcc.dg/predict-3.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-3.c(revision 0)
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options -O2 -fdump-tree-profile_estimate } */
+
+extern int global;
+
+int bar(int);
+
+void foo (int bound)
+{
+  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 { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-4.c
===
--- gcc/testsuite/gcc.dg/predict-4.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-4.c(revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options -O2 -fdump-tree-profile_estimate } */
+
+extern int global;
+
+int bar(int);
+
+void foo (int bound)
+{
+  int i, ret = 0;
+  for (i = 0; i  10; i++)
+{
+  if (i  5)
+   global += bar (i);
+}
+}
+
+/* { dg-final { scan-tree-dump loop iv compare heuristics: 50.0%
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 0)
+++ gcc/testsuite/gcc.dg/predict-1.c(revision 0)
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options -O2 -fdump-tree-profile_estimate } */
+
+extern int global;
+
+int bar(int);
+
+void foo (int bound)
+{
+  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 { cleanup-tree-dump profile_estimate } } */
Index: gcc/testsuite/gcc.dg/predict-5.c
===
--- gcc/testsuite/gcc.dg/predict-5.c(revision 0)
+++ gcc/testsuite/gcc.dg/predict-5.c(revision 0)
@@ -0,0 +1,25 @@
+/* { 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 0)
+++ gcc/testsuite/gcc.dg/predict-2.c(revision 0)
@@ -0,0 +1,27 @@
+/* { 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  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)
+   global += 

patch ping: Add static branch predict heuristic of comparing IV to loop_bound variable

2012-01-17 Thread Dehao Chen
http://gcc.gnu.org/ml/gcc-patches/2012-01/msg00377.html

Thanks!
Dehao