From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 5E0483858C2F for ; Mon, 25 Sep 2023 08:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E0483858C2F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 76005282602; Mon, 25 Sep 2023 10:52:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1695631931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZulKsoO4ZSgzj6wdE0rQSBM1NWp5IIs6A/PWyzq3zxY=; b=E3Yzvr9yGdcu+n3x4mYDRmpfm9U6RmOu5YG6eS6sFFUyeDKi1Lz/K2GPdO80ecw3z+tVnl 1va8ErYckJQuNvwN0oooWARd4dbPmvEZg2XoMp5Su2vV5VWnMnWi/SGufTMlmw+u6m67X4 z4NPsDr4KT9LJDBMe4hadgcy7kga/XM= Date: Mon, 25 Sep 2023 10:52:11 +0200 From: Jan Hubicka To: Martin Jambor Cc: GCC Patches Subject: Re: [PATCH] ipa: Self-DCE of uses of removed call LHSs (PR 108007) Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,JMQ_SPF_NEUTRAL,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > >> 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 > >> > >> 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 > >> > >> 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 *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