From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 55BAB3850B23 for ; Tue, 13 Dec 2022 18:34:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55BAB3850B23 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail 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 485B122816; Tue, 13 Dec 2022 18:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1670956495; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MIN1O6/dDs3b5dQq+nMbFaDlr+GUgVAjKC59aWBl2kk=; b=U2v5h2Cq0SODRWqGubsGNYxHtamhj3yZWx7TflaI64N0grOYi6i3Ag92JVo4OLJX1yZUtv AQUaAZHsyMt+zZORIrlI11ycNmzpX/aqpdPquEUmjtwcqzXZpwTiAR5DVxBNcfxNW9/be+ 1PjrlW/GePoJ2fksP2PU+qkvPhgGkOo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1670956495; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MIN1O6/dDs3b5dQq+nMbFaDlr+GUgVAjKC59aWBl2kk=; b=jELIV8a5VU+gauxBftIjfl9UMwLMrH4f9BQWmxwGQWqvt+KnVXAFN1RlpQesTrYdPFk72/ /bCPpa2STa+R+ZBQ== 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 3BEEE138F9; Tue, 13 Dec 2022 18:34:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8A6bDs/FmGOkdgAAMHmgww (envelope-from ); Tue, 13 Dec 2022 18:34:55 +0000 From: Martin Jambor To: Jan Hubicka Cc: GCC Patches Subject: Re: [PATCH 3/9] ipa-cp: Leave removal of unused parameters to IPA-SRA In-Reply-To: References: User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Tue, 13 Dec 2022 19:34:54 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, On Mon, Dec 12 2022, Jan Hubicka wrote: >> [...] >> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc >> index cc031ebed0f..172ea353c49 100644 >> --- a/gcc/ipa-cp.cc >> +++ b/gcc/ipa-cp.cc >> @@ -3722,7 +3722,10 @@ estimate_local_effects (struct cgraph_node *node) >> &removable_params_cost); >> int devirt_bonus = devirtualization_time_bonus (node, &avals); >> if (always_const || devirt_bonus >> - || (removable_params_cost && node->can_change_signature)) >> + || (removable_params_cost >> + && node->can_change_signature >> + /* If IPA-SRA can do it, it can do it better. */ >> + && !node->can_be_local_p ())) > Perhaps we could dump that into dump file (i.e. not cloning because > ipa-sra will do it later). That could save me from debugging session > in future :) > OK with that change. > Honza OK, I plan to commit the following after a last round of testing. Thanks! Martin Looking at some benchmarks I have noticed many cases when IPA-CP cloned a function for all contexts just because it knew that some parameters were not used at all. Then IPA-SRA looked at the function and cloned it again to split another parameter or two. The latter pass is better equipped to detect when parameters can be altogether removed and so the IPA-CP cloning was for no good reason. This patch simply alters the IPA-CP not to do that in the situations where IPA-SRA can (for nodes which can be made local) with additional dumping requested by Honza. gcc/ChangeLog: 2022-12-13 Martin Jambor * ipa-cp.cc (clone_for_param_removal_p): New function. (estimate_local_effects): Call it before considering cloning just to remove unused parameters. --- gcc/ipa-cp.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index cc031ebed0f..300bec54bbd 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -3700,6 +3700,29 @@ get_max_overall_size (cgraph_node *node) return max_new_size; } +/* Return true if NODE should be cloned just for a parameter removal, possibly + dumping a reason if not. */ + +static bool +clone_for_param_removal_p (cgraph_node *node) +{ + if (!node->can_change_signature) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " Not considering cloning to remove parameters, " + "function cannot change signature.\n"); + return false; + } + if (node->can_be_local_p ()) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " Not considering cloning to remove parameters, " + "IPA-SRA can do it potentially better.\n"); + return false; + } + return true; +} + /* Iterate over known values of parameters of NODE and estimate the local effects in terms of time and size they have. */ @@ -3722,7 +3745,7 @@ estimate_local_effects (struct cgraph_node *node) &removable_params_cost); int devirt_bonus = devirtualization_time_bonus (node, &avals); if (always_const || devirt_bonus - || (removable_params_cost && node->can_change_signature)) + || (removable_params_cost && clone_for_param_removal_p (node))) { struct caller_statistics stats; ipa_call_estimates estimates; -- 2.38.1