public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Martin Jambor <mjambor@suse.cz>, GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Jan Hubicka <jh@suse.cz>
Subject: Re: [PATCH] ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
Date: Thu, 10 Mar 2022 08:43:14 +0100	[thread overview]
Message-ID: <1032cadf-ae9f-0120-1dfb-d63a75714a28@suse.cz> (raw)
In-Reply-To: <ri6mti0glji.fsf@suse.cz>

On 3/8/22 22:51, Martin Jambor wrote:
> Hi,
> 
> when writing the patch that downgrades address-taken references to
> load references when IPA-CP can prove that all uses of the taken
> address ends up in loads, I unfortunately did not take into account
> that find_more_scalar_values_for_callers_subset now happily adds
> self-recursive edges to the set of callers which should be immediately
> redirected (originally recursion was meant to be handled as edge
> redirection in a second pass over the SCC).
> 
> The code as it is can now decrement the referece counters too many
> times.  This can remedied by removing self-recursive edges earlier, we
> already do it because of thunk expansion issues, and so this patch
> does exactly that.
> 
> Bootstrapped and LTO-bootstrapped and tested on x86_64-linux.  OK for
> master?

Yes, thanks.

Martin

> 
> Thanks,
> 
> Martin
> 
> 
> gcc/ChangeLog:
> 
> 2022-03-07  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR ipa/104813
> 	* ipa-cp.cc (create_specialized_node): Move removal of
> 	self-recursive calls from callers vector before refrence
> 	adjustments.
> 
> gcc/testsuite/ChangeLog:
> 
> 2022-03-07  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR ipa/104813
> 	* gcc.dg/ipa/pr104813.c: New test.
> ---
>   gcc/ipa-cp.cc                       | 20 +++++++++---------
>   gcc/testsuite/gcc.dg/ipa/pr104813.c | 32 +++++++++++++++++++++++++++++
>   2 files changed, 42 insertions(+), 10 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/ipa/pr104813.c
> 
> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
> index 453e9c93cc3..18047c209a8 100644
> --- a/gcc/ipa-cp.cc
> +++ b/gcc/ipa-cp.cc
> @@ -5099,6 +5099,16 @@ create_specialized_node (struct cgraph_node *node,
>     else
>       new_adjustments = NULL;
>   
> +  auto_vec<cgraph_edge *, 2> self_recursive_calls;
> +  for (i = callers.length () - 1; i >= 0; i--)
> +    {
> +      cgraph_edge *cs = callers[i];
> +      if (cs->caller == node)
> +	{
> +	  self_recursive_calls.safe_push (cs);
> +	  callers.unordered_remove (i);
> +	}
> +    }
>     replace_trees = cinfo ? vec_safe_copy (cinfo->tree_map) : NULL;
>     for (i = 0; i < count; i++)
>       {
> @@ -5129,16 +5139,6 @@ create_specialized_node (struct cgraph_node *node,
>         if (replace_map)
>   	vec_safe_push (replace_trees, replace_map);
>       }
> -  auto_vec<cgraph_edge *, 2> self_recursive_calls;
> -  for (i = callers.length () - 1; i >= 0; i--)
> -    {
> -      cgraph_edge *cs = callers[i];
> -      if (cs->caller == node)
> -	{
> -	  self_recursive_calls.safe_push (cs);
> -	  callers.unordered_remove (i);
> -	}
> -    }
>   
>     unsigned &suffix_counter = clone_num_suffixes->get_or_insert (
>   			       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (
> diff --git a/gcc/testsuite/gcc.dg/ipa/pr104813.c b/gcc/testsuite/gcc.dg/ipa/pr104813.c
> new file mode 100644
> index 00000000000..34f413e3823
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ipa/pr104813.c
> @@ -0,0 +1,32 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3"  } */
> +
> +int a, b, c, d, *e;
> +void f(int h) {
> +  if (b) {
> +    int g;
> +    while (g++)
> +      d = *e;
> +    e++;
> +  }
> +}
> +static void i();
> +static void j(int *h, int k, int *l) {
> +  if (c) {
> +    int *o = h, m;
> +    f(*l);
> +    i(m);
> +    j(o, 1, o);
> +    for (;;)
> +      ;
> +  }
> +}
> +void i() {
> +  int *n = &a;
> +  while (1)
> +    j(n, 1, n);
> +}
> +int main() {
> +  j(&a, 0, &a);
> +  return 0;
> +}


      reply	other threads:[~2022-03-10  7:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 21:51 Martin Jambor
2022-03-10  7:43 ` Martin Liška [this message]

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=1032cadf-ae9f-0120-1dfb-d63a75714a28@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jh@suse.cz \
    --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).