From patchwork Tue Oct 19 04:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46371 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 A42D23858411 for ; Tue, 19 Oct 2021 04:55:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A42D23858411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634619336; bh=Qnysdakp94+4/dB3LpMBmbu6l1iDcnxujjymM/RrKrg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jnOKsInULWrP6CvLOQlXeXyHQr8xmSDaQm30DsA7XDKlUfkvyoxVTL3CYcAqMCUyG +barlRQAEhZd+feW5isduwu25Y8GKKAsQWi/5e0GuuyZD8/AvEpiE6FiRaH6rE+5Jo ks/f0m9dX0H/UxNidhJUv/sB+mR/ZsU7OfCWyRHk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 8DE403858C27 for ; Tue, 19 Oct 2021 04:54:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8DE403858C27 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19J2rhHu009720 for ; Mon, 18 Oct 2021 21:54:10 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 3bsnmq0chy-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 18 Oct 2021 21:54:10 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 18 Oct 2021 21:54:09 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 18 Oct 2021 21:54:09 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 4DA493F7084; Mon, 18 Oct 2021 21:54:09 -0700 (PDT) To: Subject: [PATCH 1/4] Add dump prints when execute_fixup_cfg removes a write only var store. Date: Mon, 18 Oct 2021 21:54:01 -0700 Message-ID: <1634619244-18969-2-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634619244-18969-1-git-send-email-apinski@marvell.com> References: <1634619244-18969-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: HIEkwXpUatxpJ5Cgvz78Vke24OvggmIB X-Proofpoint-ORIG-GUID: HIEkwXpUatxpJ5Cgvz78Vke24OvggmIB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-18_07,2021-10-18_01,2020-04-07_01 X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski While debugging PR 102703, I found it was hard to figure out where the store was being removed as there was no pass which was outputting why the store was removed. This adds to execute_fixup_cfg the output. Also note most of removals happen when execute_fixup_cfg is called from the inliner. gcc/ChangeLog: * tree-cfg.c (execute_fixup_cfg): Output when the statement is removed when it is a write only var. --- gcc/tree-cfg.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 4b4b0b52d9a..b78e4564e4d 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9737,6 +9737,13 @@ execute_fixup_cfg (void) && (TREE_STATIC (lhs) || DECL_EXTERNAL (lhs)) && varpool_node::get (lhs)->writeonly) { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Removing statement, writes" + " to write only var:\n"); + print_gimple_stmt (dump_file, stmt, 0, + TDF_VOPS|TDF_MEMSYMS); + } unlink_stmt_vdef (stmt); gsi_remove (&gsi, true); release_defs (stmt); From patchwork Tue Oct 19 04:54:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46372 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 EC1313858408 for ; Tue, 19 Oct 2021 04:56:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC1313858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634619393; bh=WAIgdFsfwVsDMU+icq0HdiCOL5+QjnbEBsPD2wELa+g=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=YxLHMF/WvSOVKxSuUD8m8inemGOUBLCG/xUmlKxmP1iwy9u8NhlqZlh2nYAPMxfYC IOo8R5LtKbI6Chgq7LBtwSfL+KaWbJHqu/P2bmuRCpmTlF1cvA319a8DCPOiyCSN0j EpKUFTvAF4EeIMnFlHLhWB5ctzWZ5LV900OqzYo8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 7B6663858408 for ; Tue, 19 Oct 2021 04:54:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B6663858408 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19J0kZNE030315 for ; Mon, 18 Oct 2021 21:54:12 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 3bsfk49pky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 18 Oct 2021 21:54:11 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 18 Oct 2021 21:54:09 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 18 Oct 2021 21:54:09 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id A48FA3F7064; Mon, 18 Oct 2021 21:54:09 -0700 (PDT) To: Subject: [PATCH 2/4] Remove outdated comment about execute_fixup_cfg Date: Mon, 18 Oct 2021 21:54:02 -0700 Message-ID: <1634619244-18969-3-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634619244-18969-1-git-send-email-apinski@marvell.com> References: <1634619244-18969-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: YSBuE1yRRYTcZzq1tndPssynHBTyI6L5 X-Proofpoint-GUID: YSBuE1yRRYTcZzq1tndPssynHBTyI6L5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-18_07,2021-10-18_01,2020-04-07_01 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski The comment about execute_fixup_cfg not being able to run as a standalone pass is not true for a long time now. It has been a standalone pass for a while now. gcc/ChangeLog: * tree-cfg.c (execute_fixup_cfg): Remove comment about standalone pass. --- gcc/tree-cfg.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index b78e4564e4d..c20fc4980c6 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9669,10 +9669,7 @@ make_pass_warn_unused_result (gcc::context *ctxt) /* IPA passes, compilation of earlier functions or inlining might have changed some properties, such as marked functions nothrow, pure, const or noreturn. - Remove redundant edges and basic blocks, and create new ones if necessary. - - This pass can't be executed as stand alone pass from pass manager, because - in between inlining and this fixup the verify_flow_info would fail. */ + Remove redundant edges and basic blocks, and create new ones if necessary. */ unsigned int execute_fixup_cfg (void) From patchwork Tue Oct 19 04:54:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46373 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 0FCD73858426 for ; Tue, 19 Oct 2021 04:57:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FCD73858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634619449; bh=5H77TyHAoWEVHNt3LticEG6kOQ8jcsLNONdRVKIfD2g=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=r813f9VvAmzwlWIbNQy6e7F2cGqe7jCKYzkhaDAh85JpfGOl0ebsE6JuROSf407bU 5ud3b0iIRzhXblZFkY1UbsCLUWYmGf6mpyk+Ns9tz9u29SDwyl2xrUB6O0MauGmXVn aQ6Nl99EQ3hQXW/hL/zuiG9r0RG/mLSi7N0tS0Vs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id B15AB385840B for ; Tue, 19 Oct 2021 04:54:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B15AB385840B Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19J0kZNF030315 for ; Mon, 18 Oct 2021 21:54:12 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 3bsfk49pky-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 18 Oct 2021 21:54:12 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 18 Oct 2021 21:54:10 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 18 Oct 2021 21:54:10 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 06A6E3F7083; Mon, 18 Oct 2021 21:54:09 -0700 (PDT) To: Subject: [PATCH 3/4] Factor out removal of write only stores from execute_fixup_cfg Date: Mon, 18 Oct 2021 21:54:03 -0700 Message-ID: <1634619244-18969-4-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634619244-18969-1-git-send-email-apinski@marvell.com> References: <1634619244-18969-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: WeK2aXq5lRjmgvbQzkD-pvr9llfuOL_y X-Proofpoint-GUID: WeK2aXq5lRjmgvbQzkD-pvr9llfuOL_y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-18_07,2021-10-18_01,2020-04-07_01 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski To make it easier to fix PR 102703, factoring this code out to its own function makes it easier to read and less indentions too. gcc/ChangeLog: * tree-cfg.c (maybe_remove_writeonly_store): New function factored out from ... (execute_fixup_cfg): Here. Call maybe_remove_writeonly_store. --- gcc/tree-cfg.c | 62 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index c20fc4980c6..dbbf6beb6e4 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9666,6 +9666,38 @@ make_pass_warn_unused_result (gcc::context *ctxt) return new pass_warn_unused_result (ctxt); } +/* Maybe Remove stores to variables we marked write-only. + Return true if a store was removed. */ +static bool +maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt) +{ + /* Keep access when store has side effect, i.e. in case when source + is volatile. */ + if (!gimple_store_p (stmt) + || gimple_has_side_effects (stmt) + || optimize_debug) + return false; + + tree lhs = get_base_address (gimple_get_lhs (stmt)); + + if (!VAR_P (lhs) + || (!TREE_STATIC (lhs) && !DECL_EXTERNAL (lhs)) + || !varpool_node::get (lhs)->writeonly) + return false; + + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Removing statement, writes" + " to write only var:\n"); + print_gimple_stmt (dump_file, stmt, 0, + TDF_VOPS|TDF_MEMSYMS); + } + unlink_stmt_vdef (stmt); + gsi_remove (&gsi, true); + release_defs (stmt); + return true; +} + /* IPA passes, compilation of earlier functions or inlining might have changed some properties, such as marked functions nothrow, pure, const or noreturn. @@ -9721,33 +9753,13 @@ execute_fixup_cfg (void) todo |= TODO_cleanup_cfg; } - /* Remove stores to variables we marked write-only. - Keep access when store has side effect, i.e. in case when source - is volatile. */ - if (gimple_store_p (stmt) - && !gimple_has_side_effects (stmt) - && !optimize_debug) + /* Remove stores to variables we marked write-only. */ + if (maybe_remove_writeonly_store (gsi, stmt)) { - tree lhs = get_base_address (gimple_get_lhs (stmt)); - - if (VAR_P (lhs) - && (TREE_STATIC (lhs) || DECL_EXTERNAL (lhs)) - && varpool_node::get (lhs)->writeonly) - { - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Removing statement, writes" - " to write only var:\n"); - print_gimple_stmt (dump_file, stmt, 0, - TDF_VOPS|TDF_MEMSYMS); - } - unlink_stmt_vdef (stmt); - gsi_remove (&gsi, true); - release_defs (stmt); - todo |= TODO_update_ssa | TODO_cleanup_cfg; - continue; - } + todo |= TODO_update_ssa | TODO_cleanup_cfg; + continue; } + /* For calls we can simply remove LHS when it is known to be write-only. */ if (is_gimple_call (stmt) From patchwork Tue Oct 19 04:54:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46374 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 4288B3858408 for ; Tue, 19 Oct 2021 04:58:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4288B3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634619505; bh=zDaC8bX1Wo3QgMjvQDuAXy9Yqf0Vyc1k/AcA6MEk+9U=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Dcvqxs3E1/a1cmf0Fnb8E/DEwk18lVWsc9wOq0Gi7j99WJyImN5cM1IYVKR/3HHcY VplA5rH/t4fAed8QP132fE9jSkakn2oQv6SUBNVHjFE6tJI+eQm+aVVd+xD7FHfSSm 6eItXA4hSCFo2UZeBqtddrEULwsliIXuYqG9CQ4Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 046073858C27 for ; Tue, 19 Oct 2021 04:54:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 046073858C27 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19J0kaOQ030337 for ; Mon, 18 Oct 2021 21:54:12 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3bsfk49pm0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 18 Oct 2021 21:54:12 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 18 Oct 2021 21:54:10 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 18 Oct 2021 21:54:10 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 6D7703F7084; Mon, 18 Oct 2021 21:54:10 -0700 (PDT) To: Subject: [PATCH 4/4] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement Date: Mon, 18 Oct 2021 21:54:04 -0700 Message-ID: <1634619244-18969-5-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1634619244-18969-1-git-send-email-apinski@marvell.com> References: <1634619244-18969-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 06PWreJ8DEy3MbMmrQmc85WjYJPLGxp- X-Proofpoint-GUID: 06PWreJ8DEy3MbMmrQmc85WjYJPLGxp- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-18_07,2021-10-18_01,2020-04-07_01 X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski Instead of putting a full blow DCE after execute_fixup_cfg, it makes sense to try to remove the defining statement for the store that is being removed. Right now we only handle PHI node statements as there needs no extra checks except for it is only used once in the store statement. gcc/ChangeLog: * tree-cfg.c (maybe_remove_writeonly_store): Remove defining (PHI) statement of the store if possible. --- gcc/tree-cfg.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index dbbf6beb6e4..d9efdc220ca 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9692,6 +9692,41 @@ maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt) print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS); } + + /* Remove the statement defining the rhs if it was only + used by this statement. */ + if (gimple_assign_single_p (stmt)) + { + tree rhs = gimple_assign_rhs1 (stmt); + gimple *use_stmt; + use_operand_p use_p; + gimple *stmt1; + + + if (TREE_CODE (rhs) == SSA_NAME + && single_imm_use (rhs, &use_p, &use_stmt) + && (stmt1 = SSA_NAME_DEF_STMT (rhs)) + /* For now only handle PHI nodes. + FIXME: this should handle more. */ + && gimple_code (stmt1) == GIMPLE_PHI) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Removing defining statement:\n"); + print_gimple_stmt (dump_file, stmt1, 0, + TDF_VOPS|TDF_MEMSYMS); + } + gimple_stmt_iterator gsi_for_def; + gsi_for_def = gsi_for_stmt (stmt1); + if (gimple_code (stmt1) == GIMPLE_PHI) + remove_phi_node (&gsi_for_def, true); + else + { + gsi_remove (&gsi_for_def, true); + release_defs (stmt1); + } + } + } unlink_stmt_vdef (stmt); gsi_remove (&gsi, true); release_defs (stmt);