2013-10-02 Rong Xu
* predict.c (tree_predict_by_opcode): Get the probablity
for builtin_expect from param builtin_expect_probability.
* params.def (BUILTIN_EXPECT_PROBABILITY): New parameter.
* predict.def (PRED_BUILTIN_EXPECT_RELAXED): Fix comments.
* doc/invoke.texi: Add documentation for builtin-expect-probability.
Index: predict.c
===================================================================
--- predict.c (revision 203137)
+++ predict.c (working copy)
@@ -1995,11 +1995,12 @@ tree_predict_by_opcode (basic_block bb)
BITMAP_FREE (visited);
if (val)
{
+ int percent = PARAM_VALUE (BUILTIN_EXPECT_PROBABILITY);
+
+ gcc_assert (percent >= 0 && percent <= 100);
if (integer_zerop (val))
- predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, NOT_TAKEN);
- else
- predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, TAKEN);
- return;
+ percent = 100 - percent;
+ predict_edge (then_edge, PRED_BUILTIN_EXPECT, HITRATE (percent));
}
/* Try "pointer heuristic."
A comparison ptr == 0 is predicted as false.
Index: params.def
===================================================================
--- params.def (revision 203137)
+++ params.def (working copy)
@@ -398,6 +398,19 @@ DEFPARAM(PARAM_MAX_PREDICTED_ITERATIONS,
"max-predicted-iterations",
"The maximum number of loop iterations we predict statically",
100, 0, 0)
+
+/* This parameter controls the probability of builtin_expect. The default
+ value is 90%. This empirical value is obtained through the weighted
+ probability of FDO counters (with the FDO count value as the weight)
+ in some real world programs:
+ (1) Google performance test benchmarks: the probability is 0.9081.
+ (2) Linux 3.3 kernel running Google search workload: the probability
+ is 0.8717. */
+
+DEFPARAM(BUILTIN_EXPECT_PROBABILITY,
+ "builtin-expect-probability",
+ "Set the estimated probability in percentage for builtin expect. The default value is 90% probability.",
+ 90, 0, 100)
DEFPARAM(TRACER_DYNAMIC_COVERAGE_FEEDBACK,
"tracer-dynamic-coverage-feedback",
"The percentage of function, weighted by execution frequency, that must be covered by trace formation. Used when profile feedback is available",
Index: predict.def
===================================================================
--- predict.def (revision 203137)
+++ predict.def (working copy)
@@ -57,7 +57,10 @@ DEF_PREDICTOR (PRED_UNCONDITIONAL, "unconditional
DEF_PREDICTOR (PRED_LOOP_ITERATIONS, "loop iterations", PROB_ALWAYS,
PRED_FLAG_FIRST_MATCH)
-/* Hints dropped by user via __builtin_expect feature. */
+/* Hints dropped by user via __builtin_expect feature. Note: the
+ probability of PROB_VERY_LIKELY is now overwritten by param
+ builtin_expect_probability with a default value of HITRATE(90).
+ Refer to param.def for details. */
DEF_PREDICTOR (PRED_BUILTIN_EXPECT, "__builtin_expect", PROB_VERY_LIKELY,
PRED_FLAG_FIRST_MATCH)
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 203137)
+++ doc/invoke.texi (working copy)
@@ -9491,6 +9491,11 @@ The known number of iterations is predicted correc
the unknown number of iterations average to roughly 10. This means that the
loop without bounds appears artificially cold relative to the other one.
+@item builtin-expect-probability
+Control the probability of the expression having the specified value. This
+parameter takes a percentage (i.e. 0 ... 100) as input.
+The default probability of 90 is obtained empirically.
+
@item align-threshold
Select fraction of the maximal frequency of executions of a basic block in