From: Richard Biener <richard.guenther@gmail.com>
To: Andrew Pinski <apinski@marvell.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement
Date: Thu, 21 Oct 2021 09:40:41 +0200 [thread overview]
Message-ID: <CAFiYyc3aNPhyAsueOjY8ohhHdbf=7XOWV4WY3kwGmVA-gN5ABw@mail.gmail.com> (raw)
In-Reply-To: <1634795547-24044-1-git-send-email-apinski@marvell.com>
On Thu, Oct 21, 2021 at 7:53 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> 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.
OK.
Thanks,
Richard.
> 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
>
prev parent reply other threads:[~2021-10-21 7:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 5:52 apinski
2021-10-21 7:40 ` Richard Biener [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFiYyc3aNPhyAsueOjY8ohhHdbf=7XOWV4WY3kwGmVA-gN5ABw@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=apinski@marvell.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).