From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1611) id C2607383F226; Wed, 14 Dec 2022 00:04:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2607383F226 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670976271; bh=77tJ9jR7tsi1Be5Qqhnz5AO65Wen1xbgnabMkcEzRUw=; h=From:To:Subject:Date:From; b=MmUP0imavPPSbiKPe5Xb/lFp1x6brZQlKv7BqQXnnw6bgYfFcGxCzN8aHbDwkvg6h eRADkVoRWYG1SzXVBtQ6a3howp0T6GH9SIf3UAPXHMvcRTxITwnzBSASekx3xkua79 62aYJfsZO+3WxnEkLvBAA2OGJ3HjEDvLq3wT1/h4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Jambor To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4688] ipa-sra: Move caller->callee propagation before callee->caller one X-Act-Checkin: gcc X-Git-Author: Martin Jambor X-Git-Refname: refs/heads/master X-Git-Oldrev: 10478270fe0c39c59eb0f35d19356a63bdf3a2ad X-Git-Newrev: 803a91330bf20174d1cf6a164cafd97405655b82 Message-Id: <20221214000431.C2607383F226@sourceware.org> Date: Wed, 14 Dec 2022 00:04:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:803a91330bf20174d1cf6a164cafd97405655b82 commit r13-4688-g803a91330bf20174d1cf6a164cafd97405655b82 Author: Martin Jambor Date: Wed Dec 14 00:33:06 2022 +0100 ipa-sra: Move caller->callee propagation before callee->caller one 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. gcc/ChangeLog: 2022-11-11 Martin Jambor * ipa-sra.cc (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 Diff: --- gcc/ipa-sra.cc | 123 +++++++++++++++++----------------- gcc/testsuite/gcc.dg/ipa/ipa-sra-25.c | 17 +++++ 2 files changed, 78 insertions(+), 62 deletions(-) diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index 866f52e89e0..65d6417a35d 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -3926,27 +3926,74 @@ 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; - } + ifs->zap (); + } + + 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) + || v->call_for_symbol_and_aliases (retval_used_p, + NULL, true))); + ifs->m_return_ignored = !return_needed; + if (return_needed) + isra_push_node_to_stack (v, ifs, &stack); + } + + while (!stack.is_empty ()) + { + cgraph_node *node = stack.pop (); + isra_func_summary *ifs = func_sums->get (node); + gcc_checking_assert (ifs && ifs->m_queued); + ifs->m_queued = false; + + for (cgraph_edge *cs = node->callees; cs; cs = cs->next_callee) + if (ipa_edge_within_scc (cs) + && call_sums->get (cs)->m_return_returned) + { + enum availability av; + cgraph_node *callee = cs->callee->function_symbol (&av); + isra_func_summary *to_ifs = func_sums->get (callee); + if (to_ifs && to_ifs->m_return_ignored) + { + to_ifs->m_return_ignored = false; + isra_push_node_to_stack (callee, to_ifs, &stack); + } + } + } + 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) @@ -3959,7 +4006,7 @@ ipa_sra_analysis (void) /* 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) + for (cgraph_node *v : cycle_nodes) v->call_for_symbol_thunks_and_aliases (propagate_used_to_scc_callers, &stack, true); @@ -3980,7 +4027,7 @@ ipa_sra_analysis (void) do { repeat_scc_access_propagation = false; - FOR_EACH_VEC_ELT (cycle_nodes, j, v) + for (cgraph_node *v : cycle_nodes) { isra_func_summary *ifs = func_sums->get (v); if (!ifs @@ -3995,60 +4042,12 @@ ipa_sra_analysis (void) while (repeat_scc_access_propagation); if (flag_checking) - FOR_EACH_VEC_ELT (cycle_nodes, j, v) + for (cgraph_node *v : cycle_nodes) 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) - { - 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) - || v->call_for_symbol_and_aliases (retval_used_p, - NULL, true))); - ifs->m_return_ignored = !return_needed; - if (return_needed) - isra_push_node_to_stack (v, ifs, &stack); - } - - while (!stack.is_empty ()) - { - cgraph_node *node = stack.pop (); - isra_func_summary *ifs = func_sums->get (node); - gcc_checking_assert (ifs && ifs->m_queued); - ifs->m_queued = false; - - for (cgraph_edge *cs = node->callees; cs; cs = cs->next_callee) - if (ipa_edge_within_scc (cs) - && call_sums->get (cs)->m_return_returned) - { - enum availability av; - cgraph_node *callee = cs->callee->function_symbol (&av); - isra_func_summary *to_ifs = func_sums->get (callee); - if (to_ifs && to_ifs->m_return_ignored) - { - to_ifs->m_return_ignored = false; - isra_push_node_to_stack (callee, to_ifs, &stack); - } - } - } - 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; +}