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: 69422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1669155wrd; Tue, 14 Mar 2023 03:13:43 -0700 (PDT) X-Google-Smtp-Source: AK7set8AiAFyikGjSrTIe9eAc0/dmIiDbpKqqMx2zgtgFnPkN7ZMqY9PwWcA0P5Q8pxtkbLZvwr6 X-Received: by 2002:a17:906:b01:b0:8b1:3a23:8ec7 with SMTP id u1-20020a1709060b0100b008b13a238ec7mr1713756ejg.43.1678788823047; Tue, 14 Mar 2023 03:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678788823; cv=none; d=google.com; s=arc-20160816; b=HdAoWalrtA9o5I4/+4ComED7pAToKdPIbSTHoqcItpFX2nWuYCt8Y0bqiUqOiTAz+n WchFxaeDX3XxvYKSb5CsS/vME/lUt6iNQHQ12AbGhDOxdj3uDDYZA/887DCmLG9J/XLR FiIsYKOZXQAOS8V6Do8hJ7Vy1Q6uB1GAGSY9N0FAFCeZLFFgn0abgRwUoqOAq5vfm6l+ ratwzumAlWU5Tjd8hF31vIXSkjOV7w0XU0WxVRO5I+5f16Lp+O+GIles07SObJKCj4Wb t8UKo6f6dH2LyqAX1BOrbhTqVKcouM9T7WlHNNaYUqPN+B95ipEXQ7jsGQZumKo6iwMR pIsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=m1IVthEe9+1Cr4KfZBd/aZsdstpVx/TJZ1OSewi2dQg=; b=L9/J2rZgf6IH4P252D4hdcpusw/wGn3KhG6hFiALRlqypzdHhql8FsJOIvfD3Hn7Fe J0QPO2eJt6uXJl6BBwwbnR6CQ+xT4wXTNbU8uQn5jX9hXrJe2I6Z2ZE/oqEC3ghKtGfV pwJAxRFmgvXRJXglHyhBYRKz+62P0U+A+J7kM0qTKBfu5iLlaU1iAUy+DIjlpVqQ/wfX DozmMZt7N1gl5xp6dDferyWoQ7b8LBGvYP0cx9KDyLMbRCNFK2ZNbJS5CC7fehHjq07j FvN3Hyz0pto3YAJKyjiD3rA+tyTfwINCzQm08EVrza9EfCWJJyS3cI/PD5A+vQZGWUP7 7HgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=akR0RGAh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id rn25-20020a170906d93900b008da1e19114fsi2344288ejb.322.2023.03.14.03.13.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 03:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=akR0RGAh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F4003858414 for ; Tue, 14 Mar 2023 10:13:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F4003858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678788822; 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=akR0RGAhIKgc9WClI7aZcZ+c1vBy/7uxc46zMHn9lwNs+ez9mBAV+SI9yCMXh6emC mheyBbUq5bgEcOL5PAw1ADuO0qbhgSE3F/yhz40JqdGFLmw9S20sW75trJ0m9Bfp+R 2ZR9rLoYTNnGgRjM2EdM04XWc3B+fdKbVpGNokEI= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230314101342.1F4003858414@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760337668864512192?= X-GMAIL-MSGID: =?utf-8?q?1760337668864512192?= 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);