Patchwork [google,4-7] adjust single target i-call heursitic (issue7059044)

login
register
mail settings
Submitter Rong Xu
Date Jan. 5, 2013, 1:28 a.m.
Message ID <20130105012853.78D2E101023@rong.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/209592/
State New
Headers show

Comments

Rong Xu - Jan. 5, 2013, 1:28 a.m.
Hi,

This patch adjusts the single target indirect call promotion heuristics.
(1) it uses bb counts (bb_all), instead of count "all" which only counts
the targets with the same modules as the caller.
(becaue __gcov_indirect_call_callee is file scope statics). 
Using overall bb counts makes more sense here.
(2) use a prameter option to control the threshold. 
(3) change the default threshold from 75% to 67%.

Tested with google internal benchmarks and gcc regression test.

Thanks,

-Rong
 
2013-01-04  Rong Xu  <xur@google.com>

	* gcc/value-prof.c (gimple_ic_transform_single_targ):
        adjust the single_target i_call promotion heuristics.
	* gcc/params.def.h: Add new parameter options.

--
This patch is available for review at http://codereview.appspot.com/7059044
Xinliang David Li - Jan. 5, 2013, 3:42 a.m.
Need to document the parameter in doc/invoke.texi.

Ok with that change.

David

On Fri, Jan 4, 2013 at 5:28 PM, Rong Xu <xur@google.com> wrote:
> Hi,
>
> This patch adjusts the single target indirect call promotion heuristics.
> (1) it uses bb counts (bb_all), instead of count "all" which only counts
> the targets with the same modules as the caller.
> (becaue __gcov_indirect_call_callee is file scope statics).
> Using overall bb counts makes more sense here.
> (2) use a prameter option to control the threshold.
> (3) change the default threshold from 75% to 67%.
>
> Tested with google internal benchmarks and gcc regression test.
>
> Thanks,
>
> -Rong
>
> 2013-01-04  Rong Xu  <xur@google.com>
>
>         * gcc/value-prof.c (gimple_ic_transform_single_targ):
>         adjust the single_target i_call promotion heuristics.
>         * gcc/params.def.h: Add new parameter options.
> Index: gcc/value-prof.c
> ===================================================================
> --- gcc/value-prof.c    (revision 194916)
> +++ gcc/value-prof.c    (working copy)
> @@ -1491,16 +1491,20 @@ gimple_ic_transform_single_targ (gimple stmt, hist
>    gcov_type prob;
>    gimple modify;
>    struct cgraph_node *direct_call;
> +  int perc_threshold, count_threshold;
>
>    val = histogram->hvalue.counters [0];
>    count = histogram->hvalue.counters [1];
>    all = histogram->hvalue.counters [2];
>    gimple_remove_histogram_value (cfun, stmt, histogram);
> +  bb_all = gimple_bb (stmt)->count;
>
> -  if (4 * count <= 3 * all)
> +  perc_threshold = PARAM_VALUE (PARAM_SINGLE_ICALL_PROMOTE_PERCENT_THRESHOLD);
> +  count_threshold = PARAM_VALUE (PARAM_SINGLE_ICALL_PROMOTE_COUNT_THRESHOLD);
> +
> +  if (100 * count < bb_all * perc_threshold || count < count_threshold)
>      return false;
>
> -  bb_all = gimple_bb (stmt)->count;
>    /* The order of CHECK_COUNTER calls is important -
>       since check_counter can correct the third parameter
>       and we want to make count <= all <= bb_all. */
> @@ -1508,6 +1512,7 @@ gimple_ic_transform_single_targ (gimple stmt, hist
>        || check_counter (stmt, "ic", &count, &all, all))
>      return false;
>
> +  all = bb_all;
>    if (all > 0)
>      prob = (count * REG_BR_PROB_BASE + all / 2) / all;
>    else
> Index: gcc/params.def
> ===================================================================
> --- gcc/params.def      (revision 194916)
> +++ gcc/params.def      (working copy)
> @@ -907,6 +907,7 @@ DEFPARAM (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
>  /* Promote indirect call to conditional direct call only
>     when the percentage of the target count over the total
>     indirect call count is no smaller than the threshold.  */
> +/* For multi-targ indirect_call.  */
>  DEFPARAM (PARAM_ICALL_PROMOTE_PERCENT_THRESHOLD,
>           "icall-promote-target-percent-threshold",
>           "percentage threshold for direct call promotion"
> @@ -919,6 +920,19 @@ DEFPARAM (PARAM_ICALL_PROMOTE_COUNT_THRESHOLD,
>            " of a callee target",
>           1, 0, 0)
>
> +/* For single-targ indirect_call.  */
> +DEFPARAM (PARAM_SINGLE_ICALL_PROMOTE_PERCENT_THRESHOLD,
> +         "single_icall-promote-target-percent-threshold",
> +         "percentage threshold for direct call promotion"
> +          " of a callee target",
> +         67, 0, 100)
> +
> +DEFPARAM (PARAM_SINGLE_ICALL_PROMOTE_COUNT_THRESHOLD,
> +         "single_icall-promote-target_count-threshold",
> +         "call count threshold for direct call promotion"
> +          " of a callee target",
> +         1, 0, 0)
> +
>  /* 0: do not always inline icall target:
>     other value: always inline icall target when call count
>     exceeds this value.
>
> --
> This patch is available for review at http://codereview.appspot.com/7059044

Patch

Index: gcc/value-prof.c
===================================================================
--- gcc/value-prof.c	(revision 194916)
+++ gcc/value-prof.c	(working copy)
@@ -1491,16 +1491,20 @@  gimple_ic_transform_single_targ (gimple stmt, hist
   gcov_type prob;
   gimple modify;
   struct cgraph_node *direct_call;
+  int perc_threshold, count_threshold;
 
   val = histogram->hvalue.counters [0];
   count = histogram->hvalue.counters [1];
   all = histogram->hvalue.counters [2];
   gimple_remove_histogram_value (cfun, stmt, histogram);
+  bb_all = gimple_bb (stmt)->count;
 
-  if (4 * count <= 3 * all)
+  perc_threshold = PARAM_VALUE (PARAM_SINGLE_ICALL_PROMOTE_PERCENT_THRESHOLD);
+  count_threshold = PARAM_VALUE (PARAM_SINGLE_ICALL_PROMOTE_COUNT_THRESHOLD);
+
+  if (100 * count < bb_all * perc_threshold || count < count_threshold)
     return false;
 
-  bb_all = gimple_bb (stmt)->count;
   /* The order of CHECK_COUNTER calls is important -
      since check_counter can correct the third parameter
      and we want to make count <= all <= bb_all. */
@@ -1508,6 +1512,7 @@  gimple_ic_transform_single_targ (gimple stmt, hist
       || check_counter (stmt, "ic", &count, &all, all))
     return false;
 
+  all = bb_all;
   if (all > 0)
     prob = (count * REG_BR_PROB_BASE + all / 2) / all;
   else
Index: gcc/params.def
===================================================================
--- gcc/params.def	(revision 194916)
+++ gcc/params.def	(working copy)
@@ -907,6 +907,7 @@  DEFPARAM (PARAM_LOOP_INVARIANT_MAX_BBS_IN_LOOP,
 /* Promote indirect call to conditional direct call only
    when the percentage of the target count over the total
    indirect call count is no smaller than the threshold.  */
+/* For multi-targ indirect_call.  */
 DEFPARAM (PARAM_ICALL_PROMOTE_PERCENT_THRESHOLD,
 	  "icall-promote-target-percent-threshold",
 	  "percentage threshold for direct call promotion"
@@ -919,6 +920,19 @@  DEFPARAM (PARAM_ICALL_PROMOTE_COUNT_THRESHOLD,
           " of a callee target",
 	  1, 0, 0)
 
+/* For single-targ indirect_call.  */
+DEFPARAM (PARAM_SINGLE_ICALL_PROMOTE_PERCENT_THRESHOLD,
+	  "single_icall-promote-target-percent-threshold",
+	  "percentage threshold for direct call promotion"
+          " of a callee target",
+	  67, 0, 100)
+
+DEFPARAM (PARAM_SINGLE_ICALL_PROMOTE_COUNT_THRESHOLD,
+	  "single_icall-promote-target_count-threshold",
+	  "call count threshold for direct call promotion"
+          " of a callee target",
+	  1, 0, 0)
+
 /* 0: do not always inline icall target:
    other value: always inline icall target when call count
    exceeds this value.