public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Martin Jambor <mjambor@suse.cz>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Xionghu Luo <luoxhu@linux.ibm.com>
Subject: Re: [PATCH 3/4] ipa-cp: Fix updating of profile counts and self-gen value evaluation
Date: Fri, 8 Oct 2021 13:31:43 +0200	[thread overview]
Message-ID: <20211008113143.GA67072@kam.mff.cuni.cz> (raw)
In-Reply-To: <055af750e7a6bd722e55c7046b8b9a38eefa4986.1629805719.git.mjambor@suse.cz>

> For non-local nodes which can have unknown callers, the algorithm just
> takes half of the counts - we may decide that taking just a third or
> some other portion is more reasonable, but I do not think we can
> attempt anything more clever.

Can't you just sum the calling edges and subtract it from callee's
count?
> 2021-08-23  Martin Jambor  <mjambor@suse.cz>
> 
> 	* ipa-cp.c (struct caller_statistics): New fields rec_count_sum,
> 	n_nonrec_calls and itself, document all fields.
> 	(init_caller_stats): Initialize the above new fields.
> 	(gather_caller_stats): Gather self-recursive counts and calls number.
> 	(get_info_about_necessary_edges): Gather counts of self-recursive and
> 	other edges bringing in the requested value separately.
> 	(dump_profile_updates): Rework to dump info about a single node only.
> 	(lenient_count_portion_handling): New function.
> 	(struct gather_other_count_struct): New type.
> 	(gather_count_of_non_rec_edges): New function.
> 	(struct desc_incoming_count_struct): New type.
> 	(analyze_clone_icoming_counts): New function.
> 	(adjust_clone_incoming_counts): Likewise.
> 	(update_counts_for_self_gen_clones): Likewise.
> 	(update_profiling_info): Rewritten.
> 	(update_specialized_profile): Adjust call to dump_profile_updates.
> 	(create_specialized_node): Do not update profiling info.
> 	(decide_about_value): New parameter self_gen_clones, either push new
> 	clones into it or updat their profile counts.  For self-recursively
> 	generated values, use a portion of the node count instead of count
> 	from self-recursive edges to estimate goodness.
> 	(decide_whether_version_node): Gather clones for self-generated values
> 	in a new vector, update their profiles at once at the end.
> ---
>  gcc/ipa-cp.c | 543 +++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 457 insertions(+), 86 deletions(-)
> 
> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index b987d975793..53cca7aa804 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -701,20 +701,36 @@ ipcp_versionable_function_p (struct cgraph_node *node)
>  
>  struct caller_statistics
>  {
> +  /* If requested (see below), self-recursive call counts are summed into this
> +     field.  */
> +  profile_count rec_count_sum;
> +  /* The sum of all ipa counts of all the other (non-recursive) calls.  */
>    profile_count count_sum;
> +  /* Sum of all frequencies for all calls.  */
>    sreal freq_sum;
> +  /* Number of calls and hot calls respectively.  */
>    int n_calls, n_hot_calls;
> +  /* If itself is set up, also count the number of non-self-recursive
> +     calls.  */
> +  int n_nonrec_calls;
> +  /* If non-NULL, this is the node itself and calls from it should have their
> +     counts included in rec_count_sum and not count_sum.  */
> +  cgraph_node *itself;
>  };
>  
> +/* With partial train run we do not want to assume that original's count is
> +   zero whenever we redurect all executed edges to clone.  Simply drop profile
> +   to local one in this case.  In eany case, return the new value.  ORIG_NODE
> +   is the original node and its count has not been updaed yet.  */
> +
> +profile_count
> +lenient_count_portion_handling (profile_count remainder, cgraph_node *orig_node)
> +{
> +  if (remainder.ipa_p () && !remainder.ipa ().nonzero_p ()
> +      && orig_node->count.ipa_p () && orig_node->count.ipa ().nonzero_p ()
> +      && opt_for_fn (orig_node->decl, flag_profile_partial_training))
> +    remainder = remainder.guessed_local ();

I do not think you need partial training flag here.  You should see IPA
profile is mising by simply testing ipa_p predicate on relevant counts.
> +
> +/* If caller edge counts of a clone created for a self-recursive arithmetic jump
> +   function must be adjusted, do so. NODE is the node or its thunk.  */

I would add comment on why it needs to be adjusted and how.
> +
> +static void
> +adjust_clone_incoming_counts (cgraph_node *node,
> +			      desc_incoming_count_struct *desc)
> +{
> +  for (cgraph_edge *cs = node->callers; cs; cs = cs->next_caller)
> +    if (cs->caller->thunk)
> +      {
> +	adjust_clone_incoming_counts (cs->caller, desc);
> +	profile_count sum = profile_count::zero ();
> +	for (cgraph_edge *e = cs->caller->callers; e; e = e->next_caller)
> +	  if (e->count.initialized_p ())
> +	    sum += e->count.ipa ();
> +	cs->count = cs->count.combine_with_ipa_count (sum);
> +      }
> +    else if (!desc->processed_edges->contains (cs)
> +	     && cs->caller->clone_of == desc->orig)
> +      {
> +	cs->count += desc->count;
> +	if (dump_file)
> +	  {
> +	    fprintf (dump_file, "       Adjusted count of an incoming edge of "
> +		     "a clone %s -> %s to ", cs->caller->dump_name (),
> +		     cs->callee->dump_name ());
> +	    cs->count.dump (dump_file);
> +	    fprintf (dump_file, "\n");
> +	  }
> +      }
> +}

Otherwise the patch looks OK.

Honza

  reply	other threads:[~2021-10-08 11:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 11:48 [PATCH 0/4] IPA-CP profile feedback handling fixes Martin Jambor
2021-08-20 17:43 ` [PATCH 3/4] ipa-cp: Fix updating of profile counts and self-gen value evaluation Martin Jambor
2021-10-08 11:31   ` Jan Hubicka [this message]
2021-10-18 16:56     ` Martin Jambor
2021-10-27 13:18       ` Martin Jambor
2021-08-20 17:43 ` [PATCH 2/4] ipa-cp: Propagation boost for recursion generated values Martin Jambor
2021-10-06 15:49   ` Jan Hubicka
2021-10-07 14:59     ` Martin Jambor
2021-10-07 15:25       ` Jan Hubicka
2021-08-20 17:43 ` [PATCH 1/4] cgraph: Do not warn about caller count mismatches of removed functions Martin Jambor
2021-09-16 15:10   ` Martin Jambor
2021-08-23 18:49 ` [PATCH 4/4] ipa-cp: Select saner profile count to base heuristics on Martin Jambor
2021-10-06 15:33   ` Jan Hubicka
2021-10-18 17:10     ` Martin Jambor
2021-10-27 13:22       ` Martin Jambor
2021-10-27 13:20   ` Martin Jambor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211008113143.GA67072@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=luoxhu@linux.ibm.com \
    --cc=mjambor@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).