From: Jan Hubicka <hubicka@ucw.cz>
To: Martin Jambor <mjambor@suse.cz>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] ipa: Self-DCE of uses of removed call LHSs (PR 108007)
Date: Mon, 25 Sep 2023 10:52:11 +0200 [thread overview]
Message-ID: <ZRFKO9GWjXcwoeOe@kam.mff.cuni.cz> (raw)
In-Reply-To: <ri6y1h2bdic.fsf@suse.cz>
> >> 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
> >> recursivewly looks for 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.
> >>
> >> Bootstrapped and tested on x86_64-linux. OK for master? (I am not sure
> >> the problem is grave enough to warrant backporting to release branches
> >> but can do that as well if people think I should.)
> >>
> >> Thanks,
> >>
> >> Martin
> >>
> >>
> >> gcc/ChangeLog:
> >>
> >> 2023-05-11 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): Added 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 substitutin 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.
> >> ---
> >> gcc/cgraph.cc | 10 +++-
> >> gcc/cgraph.h | 9 ++-
> >> gcc/ipa-param-manipulation.cc | 85 +++++++++++++++++++++--------
> >> gcc/ipa-param-manipulation.h | 3 +-
> >> gcc/testsuite/gcc.dg/ipa/pr108007.c | 32 +++++++++++
> >> gcc/tree-inline.cc | 28 ++++++----
> >> 6 files changed, 129 insertions(+), 38 deletions(-)
> >> create mode 100644 gcc/testsuite/gcc.dg/ipa/pr108007.c
> >>
> >> +/* Remove all statements that use NAME and transitively those that use the
> >> + result of such statements. KILLED_SSAS contains the SSA_NAMEs that are
> >> + already being or have been processed and new ones need to be added to it.
> >> + The funtction only has to process situations handled by
> >> + ssa_name_only_returned_p in ipa-sra.cc with the exception that it can assume
> >> + it must never reach a use in a return statement. */
> >> +
> >> +static void
> >> +purge_transitive_uses (tree name, hash_set <tree> *killed_ssas)
> >> +{
> >> + imm_use_iterator imm_iter;
> >> + gimple *stmt;
> >> +
> >> + FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name)
> >> + {
> >> + if (gimple_debug_bind_p (stmt))
> >> + {
> >> + /* When runing within tree-inline, we will never end up here but
> >> + adding the SSAs to killed_ssas will do the trick in this case and
> >> + the respective debug statements will get reset. */
> >> +
> >> + gimple_debug_bind_reset_value (stmt);
> >> + update_stmt (stmt);
> >> + continue;
> >> + }
> >> +
> >> + tree lhs = NULL_TREE;
> >> + if (is_gimple_assign (stmt))
> >> + lhs = gimple_assign_lhs (stmt);
> >> + else if (gimple_code (stmt) == GIMPLE_PHI)
> >> + lhs = gimple_phi_result (stmt);
> >> + gcc_assert (lhs
> >> + && (TREE_CODE (lhs) == SSA_NAME)
> >> + && !gimple_vdef (stmt));
> >> +
> >> + if (!killed_ssas->contains (lhs))
> >> + {
> >> + killed_ssas->add (lhs);
> >> + purge_transitive_uses (lhs, killed_ssas);
SSA graph may be deep so this may cause stack overflow, so I think we
should use worklist here (it is also easy to do).
OK with that change.
Honza
next prev parent reply other threads:[~2023-09-25 8:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-12 12:45 Martin Jambor
2023-05-12 19:21 ` Bernhard Reutner-Fischer
2023-06-13 15:11 ` Martin Jambor
2023-06-15 9:20 ` Bernhard Reutner-Fischer
2023-09-01 13:32 ` Martin Jambor
2023-09-19 11:36 ` Martin Jambor
2023-09-25 8:52 ` Jan Hubicka [this message]
2023-10-03 17:07 ` Martin Jambor
2023-10-05 0:08 ` Maciej W. Rozycki
2023-10-05 0:09 ` Andrew Pinski
2024-01-16 12:39 Martin Jambor
2024-01-22 17:21 ` Jan Hubicka
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=ZRFKO9GWjXcwoeOe@kam.mff.cuni.cz \
--to=hubicka@ucw.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=mjambor@suse.cz \
/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).