aboutsummaryrefslogtreecommitdiff
path: root/gcc/cgraph.cc
diff options
context:
space:
mode:
authorMartin Jambor <mjambor@suse.cz>2023-10-03 18:44:51 +0200
committerMartin Jambor <mjambor@suse.cz>2023-10-03 18:48:41 +0200
commit1be18ea110a2d69570dbc494588a7c73173883be (patch)
tree5ae50ba48f37f9f02b1b7a61af65ff9e3116500f /gcc/cgraph.cc
parent7eb5ce7f58ed4a48641e1786e4fdeb2f7fb8c5ff (diff)
downloadgcc-1be18ea110a2d69570dbc494588a7c73173883be.zip
gcc-1be18ea110a2d69570dbc494588a7c73173883be.tar.gz
gcc-1be18ea110a2d69570dbc494588a7c73173883be.tar.bz2
ipa: Self-DCE of uses of removed call LHSs (PR 108007)
PR 108007 is another manifestation where we rely on DCE to clean-up after IPA-SRA and if the user explicitely switches DCE off, IPA-SRA can leave behind statements which are fed uninitialized values and trap, even though their results are themselves never used. I have already fixed this for unused parameters in callees, this bug shows that almost the same thing can happen for removed returns, on the side of callers. This means that the issue has to be fixed elsewhere, in call redirection. This patch adds a function which looks for (and through, using a work-list) uses of operations fed specific SSA names and removes them all. That would have been easy if it wasn't for debug statements during tree-inline (from which call redirection is also invoked). Debug statements are decoupled from the rest at this point and iterating over uses of SSAs does not bring them up. During tree-inline they are handled especially at the end, I assume in order to make sure that relative ordering of UIDs are the same with and without debug info. This means that during tree-inline we need to make a hash of killed SSAs, that we already have in copy_body_data, available to the function making the purging. So the patch duly does also that, making the interface slightly ugly. gcc/ChangeLog: 2023-09-27 Martin Jambor <mjambor@suse.cz> PR ipa/108007 * cgraph.h (cgraph_edge): Add a parameter to redirect_call_stmt_to_callee. * ipa-param-manipulation.h (ipa_param_adjustments): Add a parameter to modify_call. * cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): New parameter killed_ssas, pass it to padjs->modify_call. * ipa-param-manipulation.cc (purge_transitive_uses): New function. (ipa_param_adjustments::modify_call): New parameter killed_ssas. Instead of substituting uses, invoke purge_transitive_uses. If hash of killed SSAs has not been provided, create a temporary one and release SSAs that have been added to it. * tree-inline.cc (redirect_all_calls): Create id->killed_new_ssa_names earlier, pass it to edge redirection, adjust a comment. (copy_body): Release SSAs in id->killed_new_ssa_names. gcc/testsuite/ChangeLog: 2023-05-11 Martin Jambor <mjambor@suse.cz> PR ipa/108007 * gcc.dg/ipa/pr108007.c: New test.
Diffstat (limited to 'gcc/cgraph.cc')
-rw-r--r--gcc/cgraph.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index e41e5ad..b82367a 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1403,11 +1403,17 @@ cgraph_edge::redirect_callee (cgraph_node *n)
speculative indirect call, remove "speculative" of the indirect call and
also redirect stmt to it's final direct target.
+ When called from within tree-inline, KILLED_SSAs has to contain the pointer
+ to killed_new_ssa_names within the copy_body_data structure and SSAs
+ discovered to be useless (if LHS is removed) will be added to it, otherwise
+ it needs to be NULL.
+
It is up to caller to iteratively transform each "speculative"
direct call as appropriate. */
gimple *
-cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e)
+cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
+ hash_set <tree> *killed_ssas)
{
tree decl = gimple_call_fndecl (e->call_stmt);
gcall *new_stmt;
@@ -1527,7 +1533,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e)
remove_stmt_from_eh_lp (e->call_stmt);
tree old_fntype = gimple_call_fntype (e->call_stmt);
- new_stmt = padjs->modify_call (e, false);
+ new_stmt = padjs->modify_call (e, false, killed_ssas);
cgraph_node *origin = e->callee;
while (origin->clone_of)
origin = origin->clone_of;