* [PATCH] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement
@ 2021-10-21 5:52 apinski
2021-10-21 7:40 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: apinski @ 2021-10-21 5:52 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
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.
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement
2021-10-21 5:52 [PATCH] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement apinski
@ 2021-10-21 7:40 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-10-21 7:40 UTC (permalink / raw)
To: Andrew Pinski; +Cc: GCC Patches
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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-21 7:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 5:52 [PATCH] Improve maybe_remove_writeonly_store to do a simple DCE for defining statement apinski
2021-10-21 7:40 ` Richard Biener
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).