From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1611) id F25CE3872562; Wed, 14 Dec 2022 00:04:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F25CE3872562 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670976260; bh=xNo3uzXlPL4XXQ9BLSzy1JM7wbqjHc0OQL0AroIFRuQ=; h=From:To:Subject:Date:From; b=eKJK5TKnsLbiDPU6iro4JhO1OX5VrtWRfkm3vUrulhEhQD+2FUMC65elJGSQkzG0w yH2imHfqw8zWMg9WdmSGUxHemFDDMC/rnR5HcwROByqwaxBex4+Kt+rHtXQ8jYz7nS JAnDhg0ciRpkaalBPAWhQskrSFZvQa3Q/CIjH0eI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Jambor To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4686] ipa-cp: Leave removal of unused parameters to IPA-SRA X-Act-Checkin: gcc X-Git-Author: Martin Jambor X-Git-Refname: refs/heads/master X-Git-Oldrev: 4834e9360f7bf42fbeabaa20de5619e67c9fee4e X-Git-Newrev: 095a13eda2caf6842096a3ab78b2081c50fe8799 Message-Id: <20221214000420.F25CE3872562@sourceware.org> Date: Wed, 14 Dec 2022 00:04:20 +0000 (GMT) List-Id: https://gcc.gnu.org/g:095a13eda2caf6842096a3ab78b2081c50fe8799 commit r13-4686-g095a13eda2caf6842096a3ab78b2081c50fe8799 Author: Martin Jambor Date: Wed Dec 14 00:33:05 2022 +0100 ipa-cp: Leave removal of unused parameters to IPA-SRA 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. Diff: --- 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;