public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Jambor <mjambor@suse.cz>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 4/6] ipa: Multiple predicates for loop properties, with frequencies
Date: Fri, 02 Oct 2020 14:31:39 +0200	[thread overview]
Message-ID: <ri6wo08dd1w.fsf@suse.cz> (raw)
In-Reply-To: <20200929221815.GE7702@kam.mff.cuni.cz>

Hi,

On Wed, Sep 30 2020, Jan Hubicka wrote:
>> This patch enhances the ability of IPA to reason under what conditions
>> loops in a function have known iteration counts or strides because it
>> replaces single predicates which currently hold conjunction of
>> predicates for all loops with vectors capable of holding multiple
>> predicates, each with a cumulative frequency of loops with the
>> property.
>> 
>> This second property is then used by IPA-CP to much more aggressively
>> boost its heuristic score for cloning opportunities which make
>> iteration counts or strides of frequent loops compile time constant.
>> 
>> gcc/ChangeLog:
>> 
>> 2020-09-03  Martin Jambor  <mjambor@suse.cz>
>> 
>> 	* ipa-fnsummary.h (ipa_freqcounting_predicate): New type.
>> 	(ipa_fn_summary): Change the type of loop_iterations and loop_strides
>> 	to vectors of ipa_freqcounting_predicate.
>> 	(ipa_fn_summary::ipa_fn_summary): Construct the new vectors.
>> 	(ipa_call_estimates): New fields loops_with_known_iterations and
>> 	loops_with_known_strides.
>> 	* ipa-cp.c (hint_time_bonus): Multiply param_ipa_cp_loop_hint_bonus
>> 	with the expected frequencies of loops with known iteration count or
>> 	stride.
>> 	* ipa-fnsummary.c (add_freqcounting_predicate): New function.
>> 	(ipa_fn_summary::~ipa_fn_summary): Release the new vectors instead of
>> 	just two predicates.
>> 	(remap_hint_predicate_after_duplication): Replace with function
>> 	remap_freqcounting_preds_after_dup.
>> 	(ipa_fn_summary_t::duplicate): Use it or duplicate new vectors.
>> 	(ipa_dump_fn_summary): Dump the new vectors.
>> 	(analyze_function_body): Compute the loop property vectors.
>> 	(ipa_call_context::estimate_size_and_time): Calculate also
>> 	loops_with_known_iterations and loops_with_known_strides.  Adjusted
>> 	dumping accordinly.
>> 	(remap_hint_predicate): Replace with function
>> 	remap_freqcounting_predicate.
>> 	(ipa_merge_fn_summary_after_inlining): Use it.
>> 	(inline_read_section): Stream loopcounting vectors instead of two
>> 	simple predicates.
>> 	(ipa_fn_summary_write): Likewise.
>> 	* params.opt (ipa-max-loop-predicates): New parameter.
>> 	* doc/invoke.texi (ipa-max-loop-predicates): Document new param.
>> 
>> diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c
>> index 6082f34d63f..bbbb94aa930 100644
>> --- a/gcc/ipa-fnsummary.c
>> +++ b/gcc/ipa-fnsummary.c
>> @@ -310,6 +310,36 @@ set_hint_predicate (predicate **p, predicate new_predicate)
>>      }
>>  }
>>  
>> +/* Find if NEW_PREDICATE is already in V and if so, increment its freq.
>> +   Otherwise add a new item to the vector with this predicate and frerq equal
>> +   to add_freq, unless the number of predicates would exceed MAX_NUM_PREDICATES
>> +   in which case the function does nothing.  */
>> +
>> +static void
>> +add_freqcounting_predicate (vec<ipa_freqcounting_predicate, va_gc> **v,
>> +			    const predicate &new_predicate, sreal add_freq,
>> +			    unsigned max_num_predicates)
>> +{
>> +  if (new_predicate == false || new_predicate == true)
>> +    return;
>> +  ipa_freqcounting_predicate *f;
>> +  for (int i = 0; vec_safe_iterate (*v, i, &f); i++)
>> +    if (new_predicate == f->predicate)
>> +      {
>> +	f->freq += add_freq;
>> +	return;
>> +      }
>> +  if (vec_safe_length (*v) >= max_num_predicates)
>> +    /* Too many different predicates to account for.  */
>> +    return;
>> +
>> +  ipa_freqcounting_predicate fcp;
>> +  fcp.predicate = NULL;
>> +  set_hint_predicate (&fcp.predicate, new_predicate);
>> +  fcp.freq = add_freq;
>> +  vec_safe_push (*v, fcp);
>> +  return;
>> +}
>>  
>>  /* Compute what conditions may or may not hold given information about
>>     parameters.  RET_CLAUSE returns truths that may hold in a specialized copy,
>> @@ -710,13 +740,17 @@ ipa_call_summary::~ipa_call_summary ()
>>  
>>  ipa_fn_summary::~ipa_fn_summary ()
>>  {
>> -  if (loop_iterations)
>> -    edge_predicate_pool.remove (loop_iterations);
>> -  if (loop_stride)
>> -    edge_predicate_pool.remove (loop_stride);
>> +  unsigned len = vec_safe_length (loop_iterations);
>> +  for (unsigned i = 0; i < len; i++)
>> +    edge_predicate_pool.remove ((*loop_iterations)[i].predicate);
>> +  len = vec_safe_length (loop_strides);
>> +  for (unsigned i = 0; i < len; i++)
>> +    edge_predicate_pool.remove ((*loop_strides)[i].predicate);
>
> For edges predicates are pointers since most of them have no interesting
> predicate and thus NULL is more compact.  I guess here it would make
> snese to make predicates inline. Is there a problem with vectors not
> liking non-pods?
>>    vec_free (conds);
>>    vec_free (size_time_table);
>>    vec_free (call_size_time_table);
>> +  vec_free (loop_iterations);
>> +  vec_free (loop_strides);
>
> However auto_vecs should work in the brave new C++ world.

Well, the summary lives in GC memory, so I don't think I can put
auto_vecs there.

I will add a note to look into putting a predicate directly instead as a
pointer to ipa_freqcounting_predicate as a follow-up patch.

>
> The patch looks reasonable to me.  Did you check how much memory it
> consumes building bigger projects?  Also I am bit worried about our
> ability to use it reasonably in the heuristics since it is quite
> complicated value...

Thanks!

Martin

  reply	other threads:[~2020-10-02 12:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 18:12 [PATCH 0/6] IPA cleanups and IPA-CP improvements for 548.exchange2_r Martin Jambor
2020-09-21 14:25 ` [PATCH 6/6] ipa-cp: Separate and increase the large-unit parameter Martin Jambor
2020-09-29 19:30   ` Jan Hubicka
2020-09-30  6:35     ` Richard Biener
2020-09-30 16:39       ` Martin Jambor
2020-10-26 11:00   ` Tamar Christina
2020-09-21 14:25 ` [PATCH 4/6] ipa: Multiple predicates for loop properties, with frequencies Martin Jambor
2020-09-29 22:18   ` Jan Hubicka
2020-10-02 12:31     ` Martin Jambor [this message]
2020-09-21 14:25 ` [PATCH 5/6] ipa-cp: Add dumping of overall_size after cloning Martin Jambor
2020-09-29 18:39   ` Jan Hubicka
2020-09-28 18:47 ` [PATCH 1/6] ipa: Bundle vectors describing argument values Martin Jambor
2020-10-02 11:54   ` Jan Hubicka
2020-09-28 18:47 ` [PATCH 3/6] ipa: Bundle estimates of ipa_call_context::estimate_size_and_time Martin Jambor
2020-09-29 18:39   ` Jan Hubicka
2020-09-28 18:47 ` [PATCH 2/6] ipa: Introduce ipa_cached_call_context Martin Jambor
2020-09-29 18:27   ` Jan Hubicka
  -- strict thread matches above, loose matches on Subject: below --
2020-09-07 19:36 [PATCH 4/6] ipa: Multiple predicates for loop properties, with frequencies 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=ri6wo08dd1w.fsf@suse.cz \
    --to=mjambor@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.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).