aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-05-11 07:59:06 -0700
committerAndrew Pinski <apinski@marvell.com>2023-05-11 10:19:37 -0700
commit3e8f8ab5237002098e70b8cc06e51af2039078a7 (patch)
tree278a6ffbf77bc2c5b2f25b41f07c30e4c6a2b049 /gcc
parentfd95566fda0b45e92e20562321221bd2c486c089 (diff)
downloadgcc-3e8f8ab5237002098e70b8cc06e51af2039078a7.zip
gcc-3e8f8ab5237002098e70b8cc06e51af2039078a7.tar.gz
gcc-3e8f8ab5237002098e70b8cc06e51af2039078a7.tar.bz2
Improve simple_dce for phis that only used in itself
While I was looking at differences before and after r14-569-g21e2ef2dc25de3, I noticed that one phi node was not being removed. For an example, while compiling combine.cc, in expand_field_assignment, we would remove `# pos_51 = PHI <pos_221(31), pos_51(30)>` but we don't any more since pos_51 has more than zero users but in this case it is only itself. This patch improves simple_dce_from_worklist to detect that case and now we able to remove this phi statement again. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-dce.cc (simple_dce_from_worklist): For ssa names defined by a phi node with more than one uses, allow for the only uses are in that same defining statement.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/tree-ssa-dce.cc30
1 files changed, 28 insertions, 2 deletions
diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index 6554b5d..d77e541 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -2107,9 +2107,35 @@ simple_dce_from_worklist (bitmap worklist, bitmap need_eh_cleanup)
unsigned i = bitmap_clear_first_set_bit (worklist);
tree def = ssa_name (i);
- /* Removed by somebody else or still in use. */
- if (! def || ! has_zero_uses (def))
+ /* Removed by somebody else or still in use.
+ Note use in itself for a phi node is not counted as still in use. */
+ if (!def)
continue;
+ if (!has_zero_uses (def))
+ {
+ gimple *def_stmt = SSA_NAME_DEF_STMT (def);
+
+ if (gimple_code (def_stmt) != GIMPLE_PHI)
+ continue;
+
+ gimple *use_stmt;
+ imm_use_iterator use_iter;
+ bool canremove = true;
+
+ FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, def)
+ {
+ /* Ignore debug statements. */
+ if (is_gimple_debug (use_stmt))
+ continue;
+ if (use_stmt != def_stmt)
+ {
+ canremove = false;
+ break;
+ }
+ }
+ if (!canremove)
+ continue;
+ }
gimple *t = SSA_NAME_DEF_STMT (def);
if (gimple_has_side_effects (t))