From patchwork Sat Nov 12 01:46:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 60470 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F5CB389EC54 for ; Sat, 12 Nov 2022 01:47:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id B628B3896C18 for ; Sat, 12 Nov 2022 01:46:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B628B3896C18 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E98591F45F; Sat, 12 Nov 2022 01:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1668217615; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=yb7q7S6byU5rCsrko45UrveHWKyjnqQXOy/hzK04xws=; b=FkpkjOePNwp1cQ0xJ8hsSasVJhku9g5SNZBFZTmhC3+JPo5Pfa3SsCCOjOo2pG++udnC/U a959P1s870QFN9btUJBrA6J2Ujq/OHNfH8Y0weD24gUNC6HZwjiNsg94tSR6iQ8/7+Wu6U vTTIgi4SqKKLwRlrdfz2iW+WwbDVf3M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1668217615; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=yb7q7S6byU5rCsrko45UrveHWKyjnqQXOy/hzK04xws=; b=2tt0r7qHLIOjb7mh+ssHCjF+Q2gyAtEdBxlRVM3EIsIwO1P2F2maTyYsU4Dr9CCrZG+8Rl ciP3+sJtg5up/fDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DBD8213A08; Sat, 12 Nov 2022 01:46:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zfeINQ/7bmNqZAAAMHmgww (envelope-from ); Sat, 12 Nov 2022 01:46:55 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Jan Hubicka Subject: [PATCH 08/12] ipa-sra: Move caller->callee propagation before callee->caller one User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Sat, 12 Nov 2022 02:46:55 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch does not do any functional changes, it merely moves top-down propagation in the IPA-SRA WPA phase before bottom-up one. This also meant moving some preliminary checks from the latter to the former - where they need to be in their own loop over each SCC because the subsequent one looks at callers. Currently the propagations are independent (top-down is used for return value rermoval, bottom-up for parameter removal and splitting) but subsequent patches will introduce flags about parameters which should be propagated from callers first and used in splitting. I separated this change to test ir independently and make those subsequent patches cleaner. While at it, I also replaced couple of FOR_EACH_VEC_ELT macros with C++11 style iteration. Bootstrapped and tested on x86_64-linux. OK for master? Thanks, Martin gcc/ChangeLog: 2022-11-11 Martin Jambor * ipa-sra.c (ipa_sra_analysis): Move top-down analysis before bottom-up analysis. Replace FOR_EACH_VEC_ELT with C++11 iteration. gcc/testsuite/ChangeLog: 2021-12-14 Martin Jambor * gcc.dg/ipa/ipa-sra-25.c: New test --- gcc/ipa-sra.cc | 145 +++++++++++++------------- gcc/testsuite/gcc.dg/ipa/ipa-sra-25.c | 17 +++ 2 files changed, 89 insertions(+), 73 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-sra-25.c diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index e8a4cd47429..fa5a01ec07c 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -3925,95 +3925,28 @@ ipa_sra_analysis (void) auto_vec stack; int node_scc_count = ipa_reduced_postorder (order, true, NULL); - /* One sweep from callees to callers for parameter removal and splitting. */ - for (int i = 0; i < node_scc_count; i++) + /* One sweep from callers to callees for return value removal. */ + for (int i = node_scc_count - 1; i >= 0 ; i--) { cgraph_node *scc_rep = order[i]; vec cycle_nodes = ipa_get_nodes_in_cycle (scc_rep); - unsigned j; - /* Preliminary IPA function level checks and first step of parameter - removal. */ - cgraph_node *v; - FOR_EACH_VEC_ELT (cycle_nodes, j, v) + /* Preliminary IPA function level checks. */ + for (cgraph_node *v : cycle_nodes) { isra_func_summary *ifs = func_sums->get (v); if (!ifs || !ifs->m_candidate) continue; if (!ipa_sra_ipa_function_checks (v) || check_all_callers_for_issues (v)) - { - ifs->zap (); - continue; - } - if (disable_unavailable_parameters (v, ifs)) - continue; - for (cgraph_edge *cs = v->indirect_calls; cs; cs = cs->next_callee) - process_edge_to_unknown_caller (cs); - for (cgraph_edge *cs = v->callees; cs; cs = cs->next_callee) - if (!ipa_edge_within_scc (cs)) - param_removal_cross_scc_edge (cs); + ifs->zap (); } - /* Look at edges within the current SCC and propagate used-ness across - them, pushing onto the stack all notes which might need to be - revisited. */ - FOR_EACH_VEC_ELT (cycle_nodes, j, v) - v->call_for_symbol_thunks_and_aliases (propagate_used_to_scc_callers, - &stack, true); - - /* Keep revisiting and pushing until nothing changes. */ - while (!stack.is_empty ()) - { - cgraph_node *v = stack.pop (); - isra_func_summary *ifs = func_sums->get (v); - gcc_checking_assert (ifs && ifs->m_queued); - ifs->m_queued = false; - - v->call_for_symbol_thunks_and_aliases (propagate_used_to_scc_callers, - &stack, true); - } - - /* Parameter splitting. */ - bool repeat_scc_access_propagation; - do - { - repeat_scc_access_propagation = false; - FOR_EACH_VEC_ELT (cycle_nodes, j, v) - { - isra_func_summary *ifs = func_sums->get (v); - if (!ifs - || !ifs->m_candidate - || vec_safe_is_empty (ifs->m_parameters)) - continue; - for (cgraph_edge *cs = v->callees; cs; cs = cs->next_callee) - if (param_splitting_across_edge (cs)) - repeat_scc_access_propagation = true; - } - } - while (repeat_scc_access_propagation); - - if (flag_checking) - FOR_EACH_VEC_ELT (cycle_nodes, j, v) - verify_splitting_accesses (v, true); - - cycle_nodes.release (); - } - - /* One sweep from caller to callees for result removal. */ - for (int i = node_scc_count - 1; i >= 0 ; i--) - { - cgraph_node *scc_rep = order[i]; - vec cycle_nodes = ipa_get_nodes_in_cycle (scc_rep); - unsigned j; - - cgraph_node *v; - FOR_EACH_VEC_ELT (cycle_nodes, j, v) + for (cgraph_node *v : cycle_nodes) { isra_func_summary *ifs = func_sums->get (v); if (!ifs || !ifs->m_candidate) continue; - bool return_needed = (ifs->m_returns_value && (!dbg_cnt (ipa_sra_retvalues) @@ -4048,6 +3981,72 @@ ipa_sra_analysis (void) cycle_nodes.release (); } + /* One sweep from callees to callers for parameter removal and splitting. */ + for (int i = 0; i < node_scc_count; i++) + { + cgraph_node *scc_rep = order[i]; + vec cycle_nodes = ipa_get_nodes_in_cycle (scc_rep); + + /* First step of parameter removal. */ + for (cgraph_node *v : cycle_nodes) + { + isra_func_summary *ifs = func_sums->get (v); + if (!ifs || !ifs->m_candidate) + continue; + if (disable_unavailable_parameters (v, ifs)) + continue; + for (cgraph_edge *cs = v->indirect_calls; cs; cs = cs->next_callee) + process_edge_to_unknown_caller (cs); + for (cgraph_edge *cs = v->callees; cs; cs = cs->next_callee) + if (!ipa_edge_within_scc (cs)) + param_removal_cross_scc_edge (cs); + } + + /* Look at edges within the current SCC and propagate used-ness across + them, pushing onto the stack all notes which might need to be + revisited. */ + for (cgraph_node *v : cycle_nodes) + v->call_for_symbol_thunks_and_aliases (propagate_used_to_scc_callers, + &stack, true); + + /* Keep revisiting and pushing until nothing changes. */ + while (!stack.is_empty ()) + { + cgraph_node *v = stack.pop (); + isra_func_summary *ifs = func_sums->get (v); + gcc_checking_assert (ifs && ifs->m_queued); + ifs->m_queued = false; + + v->call_for_symbol_thunks_and_aliases (propagate_used_to_scc_callers, + &stack, true); + } + + /* Parameter splitting. */ + bool repeat_scc_access_propagation; + do + { + repeat_scc_access_propagation = false; + for (cgraph_node *v : cycle_nodes) + { + isra_func_summary *ifs = func_sums->get (v); + if (!ifs + || !ifs->m_candidate + || vec_safe_is_empty (ifs->m_parameters)) + continue; + for (cgraph_edge *cs = v->callees; cs; cs = cs->next_callee) + if (param_splitting_across_edge (cs)) + repeat_scc_access_propagation = true; + } + } + while (repeat_scc_access_propagation); + + if (flag_checking) + for (cgraph_node *v : cycle_nodes) + verify_splitting_accesses (v, true); + + cycle_nodes.release (); + } + ipa_free_postorder_info (); free (order); diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-25.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-25.c new file mode 100644 index 00000000000..46fc1a54571 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-25.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wmaybe-uninitialized -Werror" } */ + +int cbos(); +static int aos() { + cbos(); + return 0; +} +int cbos_ptr; +long cbos_psize; +int cbos() { + if (cbos_ptr) + return aos(); + if (cbos_psize) + return 1; + return 0; +}