From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 2998D3857C58 for ; Thu, 21 Oct 2021 05:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2998D3857C58 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 19KLUTgw008510 for ; Wed, 20 Oct 2021 22:52:34 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3btu389x1b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 20 Oct 2021 22:52:34 -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; Wed, 20 Oct 2021 22:52:32 -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; Wed, 20 Oct 2021 22:52:32 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 5E6DA3F7073; Wed, 20 Oct 2021 22:52:32 -0700 (PDT) From: To: CC: Andrew Pinski Subject: [PATCH] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement Date: Wed, 20 Oct 2021 22:52:27 -0700 Message-ID: <1634795547-24044-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: 48QCyDovW7r7-pOIACGjmzzVgMMDFQDZ X-Proofpoint-GUID: 48QCyDovW7r7-pOIACGjmzzVgMMDFQDZ 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-21_01,2021-10-20_02,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-List-Received-Date: Thu, 21 Oct 2021 05:52:36 -0000 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. Using simple_dce_from_worklist makes this easier, just mark the ssa_name on the rhs side of the store (if it was one) in a bitmap and then call simple_dce_from_worklist at the end. gcc.dg/pr36902.c needed to be changed such that the static array was no longer a static array but a global array. This is because this new dce will remove the load as it is dead. I also filed PR 102864 for the warning on dead loads. gcc/ChangeLog: * tree-cfg.c (maybe_remove_writeonly_store): Add dce_ssa_names argument. Mark the ssa-name of the rhs as one to be removed. (execute_fixup_cfg): Update call to maybe_remove_writeonly_store. Call simple_dce_from_worklist at the end to a simple dce. gcc/testsuite/ChangeLog: * gcc.dg/pr36902.c: Move buf to be a non-static variable. --- gcc/testsuite/gcc.dg/pr36902.c | 5 +---- gcc/tree-cfg.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pr36902.c b/gcc/testsuite/gcc.dg/pr36902.c index 7dafc9ac171..365a26e26b7 100644 --- a/gcc/testsuite/gcc.dg/pr36902.c +++ b/gcc/testsuite/gcc.dg/pr36902.c @@ -24,10 +24,9 @@ struct { unsigned char pcr_select[4]; } sel; +unsigned char buf[64]; int bar(void) { - static unsigned char buf[64]; - sel.size_of_select = 3; foo(buf, sel.pcr_select, sel.size_of_select); @@ -52,8 +51,6 @@ foo2(unsigned char * to, const unsigned char * from, int n) int baz(void) { - static unsigned char buf[64]; - sel.size_of_select = 5; foo2(buf, sel.pcr_select, sel.size_of_select); diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index dbbf6beb6e4..b3a27bcd17c 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -54,6 +54,7 @@ along with GCC; see the file COPYING3. If not see #include "value-prof.h" #include "tree-inline.h" #include "tree-ssa-live.h" +#include "tree-ssa-dce.h" #include "omp-general.h" #include "omp-expand.h" #include "tree-cfgcleanup.h" @@ -9669,7 +9670,8 @@ make_pass_warn_unused_result (gcc::context *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) +maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt, + bitmap dce_ssa_names) { /* Keep access when store has side effect, i.e. in case when source is volatile. */ @@ -9692,6 +9694,15 @@ maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt) print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS); } + + /* Mark ssa name defining to be checked for simple dce. */ + if (gimple_assign_single_p (stmt)) + { + tree rhs = gimple_assign_rhs1 (stmt); + if (TREE_CODE (rhs) == SSA_NAME + && !SSA_NAME_IS_DEFAULT_DEF (rhs)) + bitmap_set_bit (dce_ssa_names, SSA_NAME_VERSION (rhs)); + } unlink_stmt_vdef (stmt); gsi_remove (&gsi, true); release_defs (stmt); @@ -9714,6 +9725,7 @@ execute_fixup_cfg (void) profile_count num = node->count; profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; bool scale = num.initialized_p () && !(num == den); + auto_bitmap dce_ssa_names; if (scale) { @@ -9754,7 +9766,7 @@ execute_fixup_cfg (void) } /* Remove stores to variables we marked write-only. */ - if (maybe_remove_writeonly_store (gsi, stmt)) + if (maybe_remove_writeonly_store (gsi, stmt, dce_ssa_names)) { todo |= TODO_update_ssa | TODO_cleanup_cfg; continue; @@ -9820,6 +9832,8 @@ execute_fixup_cfg (void) && (todo & TODO_cleanup_cfg)) loops_state_set (LOOPS_NEED_FIXUP); + simple_dce_from_worklist (dce_ssa_names); + return todo; } -- 2.17.1