From patchwork Tue Apr 2 11:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1918746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=JiVIHkVs; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Tm0sIvE9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V85FX3RXrz1yYw for ; Tue, 2 Apr 2024 22:27:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A680A385841F for ; Tue, 2 Apr 2024 11:27:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 156B63858424 for ; Tue, 2 Apr 2024 11:26:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 156B63858424 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 156B63858424 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712057205; cv=none; b=HACZxWWBIBfGW5Fl2AMjWJ5fjMo2Jtqtr41m8uL8pU5Vd/o+CmVW3nLQoNOhwIn0RCNSP9i+RBjOA8eq4WNJ6FDyDrAXIMXXmUhbdLoaSH4wM+91pA0wrRESndHBlFThDwFZgcoVS6e9ue1sObxT+F6YujydUggZDpNtIe1GizI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712057205; c=relaxed/simple; bh=i4QLuKOU/HB+j7/Om/F5DTimT85Zg32zC67Px3rmaoM=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=bUM5X05CZmCb4iOaW4tgqBAUZnreQDuKzKC/fueBTrccMuofDDTGssMBqaPX+mISX3toqTnLgm70rjwEpCEsw9oAwMENnQwxf1fVkYZXXuROrinGl0dXL2SP7AprBsXeIVgFjeTPUdyTt7vqPfsWb2IRRq2fuBes9sjBmkEZ43Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 420062103A; Tue, 2 Apr 2024 11:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712057201; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=FWvZWQtBk8tYlJgq/Ii2Jng8FvmYO9woYyZYpNTr4T0=; b=JiVIHkVsUNy2NpOOc7i/xKUBUIWU7Tyb/IumKJYl9QM6SCMKpplJmOGHU3uGoBdNl+PxMz 39Q8MrEK4s2sYD7Zfb7oILteYczx36fACjwFaDwWnQzW2lDXUDK94DF775hupvCLdGakqh PEzu1EIlmNMOQ9gJKcaaMnq8dNCWfPc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712057201; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=FWvZWQtBk8tYlJgq/Ii2Jng8FvmYO9woYyZYpNTr4T0=; b=Tm0sIvE9/hiJQRDYdWJ3BHyB/7ScH2xrJmNjjR1LfJw7KF3Oodq/vKKuBo9dVxImiTck5H 2+pYY/J/jsST0UDA== Authentication-Results: smtp-out2.suse.de; none Date: Tue, 2 Apr 2024 13:26:41 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/114557 - reduce ehcleanup peak memory use MIME-Version: 1.0 X-Spam-Score: 8.87 X-Spamd-Result: default: False [8.87 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(2.99)[0.998]; MIME_GOOD(-0.10)[text/plain]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(3.50)[0.999]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.02)[54.33%] X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240402112710.A680A385841F@sourceware.org> The following reduces peak memory use for the PR114480 testcase at -O1 which is almost exclusively spent by the ehcleanup pass in allocating PHI nodes. The free_phinodes cache we maintain isn't very effective since it has effectively two slots, one for 4 and one for 9 argument PHIs and it is only ever used for allocations up to 9 arguments but we put all larger PHIs in the 9 argument bucket. This proves uneffective resulting in much garbage to be kept when incrementally growing PHI nodes by edge redirection. The mitigation is to rely on the GC freelist for larger sizes and thus immediately return all larger bucket sized PHIs to it via ggc_free. This reduces the peak memory use from 19.8GB to 11.3GB and compile-time from 359s to 168s. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. OK for trunk? I'll leave more surgery for stage1. Thanks, Richard. PR tree-optimization/114557 PR tree-optimization/114480 * tree-phinodes.cc (release_phi_node): Return PHIs from allocation buckets not covered by free_phinodes to GC. (remove_phi_node): Release the PHI LHS before freeing the PHI node. --- gcc/tree-phinodes.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/tree-phinodes.cc b/gcc/tree-phinodes.cc index ddd731323e1..5a7e4a94e57 100644 --- a/gcc/tree-phinodes.cc +++ b/gcc/tree-phinodes.cc @@ -223,6 +223,14 @@ release_phi_node (gimple *phi) delink_imm_use (imm); } + /* Immediately return the memory to the allocator when we would + only ever re-use it for a smaller size allocation. */ + if (len - 2 >= NUM_BUCKETS - 2) + { + ggc_free (phi); + return; + } + bucket = len > NUM_BUCKETS - 1 ? NUM_BUCKETS - 1 : len; bucket -= 2; vec_safe_push (free_phinodes[bucket], phi); @@ -445,9 +453,9 @@ remove_phi_node (gimple_stmt_iterator *gsi, bool release_lhs_p) /* If we are deleting the PHI node, then we should release the SSA_NAME node so that it can be reused. */ - release_phi_node (phi); if (release_lhs_p) release_ssa_name (gimple_phi_result (phi)); + release_phi_node (phi); } /* Remove all the phi nodes from BB. */