2013-09-27 Rong Xu * doc/invoke.texi: Add documentation for builtin-expect-probability-relaxed. * params.def (BUILTIN_EXPECT_PROBABILITY_RELAXED): New parameter. * predict.def (PRED_BUILTIN_EXPECT_RELAXED): New predictor. * predict.c (tree_predict_by_opcode): Use the alternate probability for builtin_expect. Default is off. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 202980) +++ doc/invoke.texi (working copy) @@ -9474,6 +9474,13 @@ 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-relaxed +The default probability for builtin-expect is 0.9996. A function call guarded by +the unlikely hint (i.e. __buildin_expect (e, 0)) will never get a change to +inline. In real world programs, this may hurt the performance. This parameter, +when set to 1, uses a relaxed probability of 0.9. This would make the +function calls in the unlikely path eligible for inline. + @item align-threshold Select fraction of the maximal frequency of executions of a basic block in Index: params.def =================================================================== --- params.def (revision 202980) +++ params.def (working copy) @@ -398,6 +398,23 @@ 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 which + has a default value of 0.9996. With this value, the calls guarded by the + unlikely hints (__buildin_expect (e, 0)) will have a frequency of 4. + and they will never get a change to inline. In real world programs, + this may hurt the performance. + We use FDO counter to measure the the weighted probability (with FDO + profile count as the weight). + (1) for google performance test benchmarks, the probability is 0.9081 + (2) for linux 3.3 kernel running google search workload, the probability + is 0.8717. + So here we introduce an alternate probability of 0.9 for builtin_expect. */ + +DEFPARAM(BUILTIN_EXPECT_PROBABILITY_RELAXED, + "builtin-expect-probability-relaxed", + "Set the estimated probability for builtin expect. By default using PROB_VERY_LIKELY, while value of 1 using HIRATE(90) probability.", + 0, 0, 1) 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 202980) +++ predict.def (working copy) @@ -60,6 +60,8 @@ DEF_PREDICTOR (PRED_LOOP_ITERATIONS, "loop iterati /* Hints dropped by user via __builtin_expect feature. */ DEF_PREDICTOR (PRED_BUILTIN_EXPECT, "__builtin_expect", PROB_VERY_LIKELY, PRED_FLAG_FIRST_MATCH) +DEF_PREDICTOR (PRED_BUILTIN_EXPECT_RELAXED, "__builtin_expect", HITRATE (90), + PRED_FLAG_FIRST_MATCH) /* Use number of loop iterations guessed by the contents of the loop. */ DEF_PREDICTOR (PRED_LOOP_ITERATIONS_GUESSED, "guessed loop iterations", Index: predict.c =================================================================== --- predict.c (revision 202980) +++ predict.c (working copy) @@ -1995,10 +1995,17 @@ tree_predict_by_opcode (basic_block bb) BITMAP_FREE (visited); if (val) { + enum br_predictor predictor; + + if (PARAM_VALUE (BUILTIN_EXPECT_PROBABILITY_RELAXED) == 0) + predictor = PRED_BUILTIN_EXPECT; + else + predictor = PRED_BUILTIN_EXPECT_RELAXED; + if (integer_zerop (val)) - predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, NOT_TAKEN); + predict_edge_def (then_edge, predictor, NOT_TAKEN); else - predict_edge_def (then_edge, PRED_BUILTIN_EXPECT, TAKEN); + predict_edge_def (then_edge, predictor, TAKEN); return; } /* Try "pointer heuristic."