diff options
author | Martin Jambor <mjambor@suse.cz> | 2021-06-28 18:20:00 +0200 |
---|---|---|
committer | Martin Jambor <mjambor@suse.cz> | 2021-06-28 18:24:54 +0200 |
commit | 2902991a6b61d473f7cb996a2b80eef4a90f8eda (patch) | |
tree | 5bd9b5d3e2e57229b505509d6e054efd0f1a780a /gcc/tree-inline.c | |
parent | 87467f45e831e8e943efdae8920453741986d355 (diff) | |
download | gcc-2902991a6b61d473f7cb996a2b80eef4a90f8eda.zip gcc-2902991a6b61d473f7cb996a2b80eef4a90f8eda.tar.gz gcc-2902991a6b61d473f7cb996a2b80eef4a90f8eda.tar.bz2 |
ipa-sra: Introduce a mini-DCE to tree-inline.c (PR 93385)
I was asked by Richi to split my fix for PR 93385 for easier review
into IPA-SRA materialization refactoring and the actual DCE addition.
This is the second part that actually contains the DCE of statements
that IPA-SRA should not leave behind because they can have problematic
side effects, even if they are useless, so that we do not depend on
tree-dce to remove them for correctness.
The patch fixes the problem by doing a def-use walk when materializing
clones, marking which statements should not be copied and which
SSA_NAMEs do not need to be computed because eventually they would be
DCEd. We do this on the original function body and tree-inline simply
does not copy statements which are "dead."
The only complication is removing dead argument calls because that
needs to be communicated to callee redirection code using the
infrastructure introduced by the previous patch.
I added all testcases of the original patch to this one, although some
probably test behavior introduced in the previous patch.
gcc/ChangeLog:
2021-05-12 Martin Jambor <mjambor@suse.cz>
PR ipa/93385
* ipa-param-manipulation.h (class ipa_param_body_adjustments): New
members m_dead_stmts and m_dead_ssas.
* ipa-param-manipulation.c
(ipa_param_body_adjustments::mark_dead_statements): New function.
(ipa_param_body_adjustments::common_initialization): Call it on
all removed but not split parameters.
(ipa_param_body_adjustments::ipa_param_body_adjustments): Initialize
new mwmbers.
(ipa_param_body_adjustments::modify_call_stmt): Remove arguments that
are dead.
* tree-inline.c (remap_gimple_stmt): Do not copy dead statements, reset
dead debug statements.
(copy_phis_for_bb): Do not copy dead PHI nodes.
gcc/testsuite/ChangeLog:
2021-03-22 Martin Jambor <mjambor@suse.cz>
PR ipa/93385
* gcc.dg/ipa/pr93385.c: New test.
* gcc.dg/ipa/ipa-sra-23.c: Likewise.
* gcc.dg/ipa/ipa-sra-24.c: Likewise.
* g++.dg/ipa/ipa-sra-4.C: Likewise.
Diffstat (limited to 'gcc/tree-inline.c')
-rw-r--r-- | gcc/tree-inline.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 4f15e57..f605e76 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1526,6 +1526,11 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) : !opt_for_fn (id->dst_fn, flag_var_tracking_assignments))) return NULL; + if (!is_gimple_debug (stmt) + && id->param_body_adjs + && id->param_body_adjs->m_dead_stmts.contains (stmt)) + return NULL; + /* Begin by recognizing trees that we'll completely rewrite for the inlining context. Our output for these trees is completely different from our input (e.g. RETURN_EXPR is deleted and morphs @@ -1790,10 +1795,15 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) if (gimple_debug_bind_p (stmt)) { + tree value; + if (id->param_body_adjs + && id->param_body_adjs->m_dead_stmts.contains (stmt)) + value = NULL_TREE; + else + value = gimple_debug_bind_get_value (stmt); gdebug *copy = gimple_build_debug_bind (gimple_debug_bind_get_var (stmt), - gimple_debug_bind_get_value (stmt), - stmt); + value, stmt); if (id->reset_location) gimple_set_location (copy, input_location); id->debug_stmts.safe_push (copy); @@ -2675,7 +2685,9 @@ copy_phis_for_bb (basic_block bb, copy_body_data *id) phi = si.phi (); res = PHI_RESULT (phi); new_res = res; - if (!virtual_operand_p (res)) + if (!virtual_operand_p (res) + && (!id->param_body_adjs + || !id->param_body_adjs->m_dead_stmts.contains (phi))) { walk_tree (&new_res, copy_tree_body_r, id, NULL); if (EDGE_COUNT (new_bb->preds) == 0) |