From patchwork Tue Mar 14 10:12:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1756762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=w/82SPbO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PbTr24R52z246l for ; Tue, 14 Mar 2023 21:13:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 615823858C2D for ; Tue, 14 Mar 2023 10:13:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 615823858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678788798; bh=m1IVthEe9+1Cr4KfZBd/aZsdstpVx/TJZ1OSewi2dQg=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=w/82SPbO+ulfDwciL0uFwJnYNSZ0h6xuh/ip6T/51z1lpeyJ84DtCVICKjI2N7zp9 hLedmjSY+jWXgS/VkxAbbqqB5EtgbEaWNUbzSdAptM7JMQAHy9kpfThjqMFSpOvwoX x+xr4vI/31nsqw1yVuAmEZDobTLW7HrriD6dZpCU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id EC96F3858D37 for ; Tue, 14 Mar 2023 10:12:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC96F3858D37 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B63DA219F8; Tue, 14 Mar 2023 10:12:58 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A50972C141; Tue, 14 Mar 2023 10:12:58 +0000 (UTC) Date: Tue, 14 Mar 2023 10:12:58 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] Remove variables only used with .DEFERRED_INIT User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230314101318.615823858C2D@sourceware.org> In PR109087 it was noticed that we rely on DSE to remove .DEFERRED_INIT when it is the only remaining use of a variable. Since DSE is imperfect and even if it were not would be limited by the amount of statements to walk the following enhances the unused var removal pass to handle .DEFERRED_INIT like CLOBBERs, thus we do not keep local variables just because they are deferred initialized. Bootstrapped and tested on x86_64-unknown-linux-gnu, for now queued for stage1 unless somebody thinks its applicable for GCC 13. * tree-ssa-live.cc (remove_unused_locals): Do not treat the .DEFERRED_INIT of a variable as use, instead remove that if it is the only use. * gcc.dg/auto-init-unused-1.c: New testcase. --- gcc/testsuite/gcc.dg/auto-init-unused-1.c | 16 ++++++++++++++++ gcc/tree-ssa-live.cc | 21 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/auto-init-unused-1.c diff --git a/gcc/testsuite/gcc.dg/auto-init-unused-1.c b/gcc/testsuite/gcc.dg/auto-init-unused-1.c new file mode 100644 index 00000000000..b7d44e6b4f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/auto-init-unused-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O -ftrivial-auto-var-init=zero -fdump-tree-ssa" } */ + +int a; +int foo (void); +int bar (void); + +void +baz (void) +{ + int *b[6]; + if (foo ()) + a |= bar (); +} + +/* { dg-final { scan-tree-dump-not "DEFERRED_INIT" "ssa" } } */ diff --git a/gcc/tree-ssa-live.cc b/gcc/tree-ssa-live.cc index c179444e8e1..9118e82b4f1 100644 --- a/gcc/tree-ssa-live.cc +++ b/gcc/tree-ssa-live.cc @@ -813,6 +813,12 @@ remove_unused_locals (void) continue; } + if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT)) + { + have_local_clobbers = true; + continue; + } + if (b) TREE_USED (b) = true; @@ -856,7 +862,7 @@ remove_unused_locals (void) to remove them if they are the only references to a local variable, but we want to retain them when there's any other. So the first pass ignores them, and the second pass (if there were any) tries to remove - them. */ + them. We do the same for .DEFERRED_INIT. */ if (have_local_clobbers) FOR_EACH_BB_FN (bb, cfun) { @@ -888,6 +894,19 @@ remove_unused_locals (void) if (b) TREE_USED (b) = true; } + else if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT)) + { + tree lhs = gimple_call_lhs (stmt); + if (DECL_P (lhs) && !is_used_p (lhs)) + { + unlink_stmt_vdef (stmt); + gsi_remove (&gsi, true); + release_defs (stmt); + continue; + } + if (b) + TREE_USED (b) = true; + } else if (gimple_debug_bind_p (stmt)) { tree var = gimple_debug_bind_get_var (stmt);