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: 66360 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 214C93858D37 for ; Tue, 14 Mar 2023 10:13:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 214C93858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678788807; 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=IJSE+04gigxzQxbqa6LRVRm+92+STxQ+QLXWIkiHglVyiLCGIYtoN9grhN1klnuya VZHeb1rv6YoD6jbpA4q9RhfTjEIfFb+uaOaWL2ag4tOEES4Lz7eAbybKU/SOh2AHjG 8NNK/xG7UVmWoOWvsS2LUGWVTqJ2IeaR9TZBdGlk= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230314101327.214C93858D37@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);