Hi, Current default probably for builtin_expect is 0.9996. This makes the freq of unlikely bb very low (4), which suppresses the inlining of any calls within those bb.
We used FDO data to measure the branch probably for the branch annotated with builtin_expert. For google internal benchmarks, the weight average (the profile count value as the weight) is 0.9081. Linux kernel is another program that is heavily annotated with builtin-expert. We measured its weight average as 0.8717, using google search as the workload. This patch sets the alternate hirate probability for builtin_expert to 90%. With the alternate hirate, we measured performance improvement for google benchmarks and Linux kernel. -Rong
2013-09-26 Rong Xu <x...@google.com> * params.def (DEFPARAM): New. * params.def: New. * predict.c (tree_predict_by_opcode): Alternate probablity hirate for builtin_expect. Index: params.def =================================================================== --- params.def (revision 202638) +++ params.def (working copy) @@ -483,6 +483,10 @@ DEFPARAM(TRACER_MIN_BRANCH_PROBABILITY, "tracer-min-branch-probability", "Stop forward growth if the probability of best edge is less than this threshold (in percent). Used when profile feedback is not available", 50, 0, 100) +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) /* The maximum number of incoming edges to consider for crossjumping. */ DEFPARAM(PARAM_MAX_CROSSJUMP_EDGES, Index: params.def =================================================================== --- params.def (revision 202638) +++ params.def (working copy) @@ -483,6 +483,10 @@ DEFPARAM(TRACER_MIN_BRANCH_PROBABILITY, "tracer-min-branch-probability", "Stop forward growth if the probability of best edge is less than this threshold (in percent). Used when profile feedback is not available", 50, 0, 100) +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) /* The maximum number of incoming edges to consider for crossjumping. */ DEFPARAM(PARAM_MAX_CROSSJUMP_EDGES, Index: predict.c =================================================================== --- predict.c (revision 202638) +++ predict.c (working copy) @@ -1950,10 +1950,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."