public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@kam.mff.cuni.cz>
To: Sergei Trofimovich <slyich@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Sergei Trofimovich <siarheit@google.com>,
	Nathan Sidwell <nathan@acm.org>
Subject: Re: [PATCH] gcov-profile: Allow negavive counts of indirect calls [PR105282]
Date: Wed, 20 Apr 2022 10:55:41 +0200	[thread overview]
Message-ID: <Yl/KjYDaSOu/MB9I@kam.mff.cuni.cz> (raw)
In-Reply-To: <20220415074855.1031369-1-slyich@gmail.com>

> From: Sergei Trofimovich <siarheit@google.com>
> 
> TOPN metrics are histograms that contain overall count and per-bucket
> count. Overall count can be nevative when two profiles merge and some
> of per-bucket metrics are dropped.
> 
> Noticed as an ICE on python PGO build where gcc crashes as:
> 
>     during IPA pass: modref
>     a.c:36:1: ICE: in stream_out_histogram_value, at value-prof.cc:340
>        36 | }
>           | ^
>     stream_out_histogram_value(output_block*, histogram_value_t*)
>             gcc/value-prof.cc:340
> 
> gcc/ChangeLog:
> 
> 	PR gcov-profile/105282
> 	* value-prof.cc (stream_out_histogram_value): Allow negavive counts
> 	on HIST_TYPE_INDIR_CALL.
> ---
>  gcc/value-prof.cc | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
> index 9785c7a03ea..4927d119aa0 100644
> --- a/gcc/value-prof.cc
> +++ b/gcc/value-prof.cc
> @@ -319,40 +319,44 @@ stream_out_histogram_value (struct output_block *ob, histogram_value hist)
>    streamer_write_bitpack (&bp);
>    switch (hist->type)
>      {
>      case HIST_TYPE_INTERVAL:
>        streamer_write_hwi (ob, hist->hdata.intvl.int_start);
>        streamer_write_uhwi (ob, hist->hdata.intvl.steps);
>        break;
>      default:
>        break;
>      }
>    for (i = 0; i < hist->n_counters; i++)
>      {
>        /* When user uses an unsigned type with a big value, constant converted
>  	 to gcov_type (a signed type) can be negative.  */
>        gcov_type value = hist->hvalue.counters[i];
>        if (hist->type == HIST_TYPE_TOPN_VALUES
>  	  || hist->type == HIST_TYPE_IOR)
>  	/* Note that the IOR counter tracks pointer values and these can have
>  	   sign bit set.  */
>  	;
> +      else if (hist->type == HIST_TYPE_INDIR_CALL && i == 0)
> +	/* 'all' counter overflow is stored as a negative value. Individual
> +	   counters and values are expected to be non-negative.  */
> +	;

I tink we can just drop the sanity check completely.  In general the
profile data may be corrupted and each use of it should be guarded to
not explode on such situation.
I added the check here long time ago while implementing the early
version of profile streaming patch. At that time some bugs was causing
counts to be negative due to weird overflows in the logic normalizing
profiles from different object files to same number of executions.

Honza
>        else
>  	gcc_assert (value >= 0);
>  
>        streamer_write_gcov_count (ob, value);
>      }
>    if (hist->hvalue.next)
>      stream_out_histogram_value (ob, hist->hvalue.next);
>  }
>  
>  /* Dump information about HIST to DUMP_FILE.  */
>  
>  void
>  stream_in_histogram_value (class lto_input_block *ib, gimple *stmt)
>  {
>    enum hist_type type;
>    unsigned int ncounters = 0;
>    struct bitpack_d bp;
>    unsigned int i;
>    histogram_value new_val;
>    bool next;
> -- 
> 2.35.1
> 

  parent reply	other threads:[~2022-04-20  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15  7:48 Sergei Trofimovich
2022-04-19  9:45 ` Martin Liška
2022-04-20  8:55 ` Jan Hubicka [this message]
2022-04-20  8:57   ` Martin Liška

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=Yl/KjYDaSOu/MB9I@kam.mff.cuni.cz \
    --to=hubicka@kam.mff.cuni.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nathan@acm.org \
    --cc=siarheit@google.com \
    --cc=slyich@gmail.com \
    /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).