predict.c: Include ipa-utils.h
authorJan Hubicka <hubicka@ucw.cz>
Sat, 25 Jun 2016 11:56:52 +0000 (13:56 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Sat, 25 Jun 2016 11:56:52 +0000 (11:56 +0000)
* predict.c: Include ipa-utils.h
(tree_bb_level_prediction): Predict recursive calls.
(tree_estimate_probability_bb): Skip inexpensive calls for call
predictor.
* predict.def (PRED_RECURSIVE_CALL): New.

* gcc.dg/predict-10.c: New test.

From-SVN: r237780

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

index a88fd1824f780329f966f839f9c66714bee15c17..121119cb2105678568f412466f641f9adf507897 100644 (file)
@@ -1,3 +1,11 @@
+2016-06-24  Jan Hubicka  <hubicka@ucw.cz>
+
+       * predict.c: Include ipa-utils.h
+       (tree_bb_level_prediction): Predict recursive calls.
+       (tree_estimate_probability_bb): Skip inexpensive calls for call
+       predictor.
+       * predict.def (PRED_RECURSIVE_CALL): New.
+
 2016-06-24  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        * config/rs6000/rs6000-builtin.def (BU_FLOAT128_2): New #define.
index d505d9c4cc80356563ead2a845c515f62998ec41..cc4302b1b7ea9925734afb52dc895ba8330a2202 100644 (file)
@@ -54,6 +54,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop-niter.h"
 #include "tree-ssa-loop.h"
 #include "tree-scalar-evolution.h"
+#include "ipa-utils.h"
 
 /* Enum with reasons why a predictor is ignored.  */
 
@@ -2425,6 +2426,9 @@ tree_bb_level_predictions (void)
                                       DECL_ATTRIBUTES (decl)))
                predict_paths_leading_to (bb, PRED_COLD_FUNCTION,
                                          NOT_TAKEN);
+             if (decl && recursive_call_p (current_function_decl, decl))
+               predict_paths_leading_to (bb, PRED_RECURSIVE_CALL,
+                                         NOT_TAKEN);
            }
          else if (gimple_code (stmt) == GIMPLE_PREDICT)
            {
@@ -2539,6 +2543,7 @@ tree_estimate_probability_bb (basic_block bb)
            {
              gimple *stmt = gsi_stmt (bi);
              if (is_gimple_call (stmt)
+                 && !gimple_inexpensive_call_p (as_a <gcall *>  (stmt))
                  /* Constant and pure calls are hardly used to signalize
                     something exceptional.  */
                  && gimple_has_side_effects (stmt))
index d3bc757bb97a8f0971cc6fa830e3b2bd8570abb2..2f6d6cd4d08822703d60ecead7593939bb4e92dc 100644 (file)
@@ -112,6 +112,9 @@ DEF_PREDICTOR (PRED_TREE_FPOPCODE, "fp_opcode (on trees)", HITRATE (90), 0)
 /* Branch guarding call is probably taken.  */
 DEF_PREDICTOR (PRED_CALL, "call", HITRATE (67), 0)
 
+/* Recursive calls are usually not taken or the function will recurse indefinitely.  */
+DEF_PREDICTOR (PRED_RECURSIVE_CALL, "recursive call", HITRATE (75), 0)
+
 /* Branch causing function to terminate is probably not taken. 
    FIXME: early return currently predicts code:
    int foo (int a)
index f373b0e27745b7195a98f9c62acc558b93f936d2..404b8144fb1146271c620b16b686f09bacb85d95 100644 (file)
@@ -1,3 +1,7 @@
+2016-06-24  Jan Hubicka  <hubicka@ucw.cz>
+
+       * gcc.dg/predict-10.c: New test.
+
 2016-06-24  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        * gcc.target/powerpc/abs128-1.c: New.
diff --git a/gcc/testsuite/gcc.dg/predict-10.c b/gcc/testsuite/gcc.dg/predict-10.c
new file mode 100644 (file)
index 0000000..a99819a
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+int
+ee(int i)
+{
+  if (i>2)
+    return (ee(i-1)+ee(i-2))/2;
+  else
+    return i;
+}
+/* { dg-final { scan-tree-dump-times "recursive call" 1 "profile_estimate"} } */