From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 08028385841F for ; Thu, 10 Mar 2022 07:43:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08028385841F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D53CB21115; Thu, 10 Mar 2022 07:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646898194; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hFWbCpwyUOcx7TdFUsijAqUo/0P4sZl3iSX5pe7Uffo=; b=Uj/ro4Xw4X6Jhox/BV5l4NXzE3vQilWdEzXpgLHK9zbWKgcS+jXMwyuz56W2nd7xtwIpyG cxsdHjZ4xsSUEn50pJSdS6zCd816a1lsgdaKTuCzO/EvhEkB4AJMh1DVau2kFWO9yKyRQt rr+H53ZoeCj9rayqdN0DbGVHB+G1nkc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646898194; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hFWbCpwyUOcx7TdFUsijAqUo/0P4sZl3iSX5pe7Uffo=; b=WVb7oMNIWLDpzIGUlCyEsLIj2DFtoUvxXk8eAHD8HSlZJqb5+646n7IX/w2/X9rSL9WaFo PBhkrFI2KZVJ3MBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BD7EF13FA3; Thu, 10 Mar 2022 07:43:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id btYhLRKsKWJCIwAAMHmgww (envelope-from ); Thu, 10 Mar 2022 07:43:14 +0000 Message-ID: <1032cadf-ae9f-0120-1dfb-d63a75714a28@suse.cz> Date: Thu, 10 Mar 2022 08:43:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] ipa-cp: Avoid adjusting references through self-recursion (PR 104813) Content-Language: en-US To: Martin Jambor , GCC Patches Cc: Jan Hubicka References: From: =?UTF-8?Q?Martin_Li=c5=a1ka?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2022 07:43:17 -0000 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 > > 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 > > 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 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 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; > +}