From 5aa91072e24c1e16a5ec641b48b64c9c9f199f13 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Sat, 13 Nov 2021 22:25:23 +0100 Subject: Implement DSE of dead functions calls storing memory. gcc/ChangeLog: 2021-11-13 Jan Hubicka * ipa-modref.c (modref_summary::modref_summary): Clear new flags. (modref_summary::dump): Dump try_dse. (modref_summary::finalize): Add FUN attribute; compute try-dse. (analyze_function): Update. (read_section): Update. (update_signature): Update. (pass_ipa_modref::execute): Update. * ipa-modref.h (struct modref_summary): * tree-ssa-alias.c (ao_ref_init_from_ptr_and_range): Export. * tree-ssa-alias.h (ao_ref_init_from_ptr_and_range): Declare. * tree-ssa-dse.c (dse_optimize_call): New function. (dse_optimize_stmt): Use it. gcc/testsuite/ChangeLog: 2021-11-13 Jan Hubicka * g++.dg/cpp1z/inh-ctor23.C: Fix template * g++.dg/ipa/ipa-icf-4.C: Fix template * gcc.dg/tree-ssa/modref-dse-1.c: New test. * gcc.dg/tree-ssa/modref-dse-2.c: New test. --- gcc/ipa-modref.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'gcc/ipa-modref.c') diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 84a32ec..3b94dc0 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -277,7 +277,7 @@ static GTY(()) fast_function_summary modref_summary::modref_summary () : loads (NULL), stores (NULL), retslot_flags (0), static_chain_flags (0), writes_errno (false), side_effects (false), global_memory_read (false), - global_memory_written (false) + global_memory_written (false), try_dse (false) { } @@ -606,6 +606,8 @@ modref_summary::dump (FILE *out) fprintf (out, " Global memory read\n"); if (global_memory_written) fprintf (out, " Global memory written\n"); + if (try_dse) + fprintf (out, " Try dse\n"); if (arg_flags.length ()) { for (unsigned int i = 0; i < arg_flags.length (); i++) @@ -662,12 +664,56 @@ modref_summary_lto::dump (FILE *out) } /* Called after summary is produced and before it is used by local analysis. - Can be called multiple times in case summary needs to update signature. */ + Can be called multiple times in case summary needs to update signature. + FUN is decl of function summary is attached to. */ void -modref_summary::finalize () +modref_summary::finalize (tree fun) { global_memory_read = !loads || loads->global_access_p (); global_memory_written = !stores || stores->global_access_p (); + + /* We can do DSE if we know function has no side effects and + we can analyse all stores. Disable dse if there are too many + stores to try. */ + if (side_effects || global_memory_written || writes_errno) + try_dse = false; + else + { + try_dse = true; + size_t i, j, k; + int num_tests = 0, max_tests + = opt_for_fn (fun, param_modref_max_tests); + modref_base_node *base_node; + modref_ref_node *ref_node; + modref_access_node *access_node; + FOR_EACH_VEC_SAFE_ELT (stores->bases, i, base_node) + { + if (base_node->every_ref) + { + try_dse = false; + break; + } + FOR_EACH_VEC_SAFE_ELT (base_node->refs, j, ref_node) + { + if (base_node->every_ref) + { + try_dse = false; + break; + } + FOR_EACH_VEC_SAFE_ELT (ref_node->accesses, k, access_node) + if (num_tests++ > max_tests + || !access_node->parm_offset_known) + { + try_dse = false; + break; + } + if (!try_dse) + break; + } + if (!try_dse) + break; + } + } } /* Get function summary for FUNC if it exists, return NULL otherwise. */ @@ -2832,7 +2878,7 @@ analyze_function (function *f, bool ipa) summary = NULL; } if (summary) - summary->finalize (); + summary->finalize (current_function_decl); if (summary_lto && !summary_lto->useful_p (ecf_flags)) { summaries_lto->remove (fnode); @@ -3553,7 +3599,7 @@ read_section (struct lto_file_decl_data *file_data, const char *data, } } if (flag_ltrans) - modref_sum->finalize (); + modref_sum->finalize (node->decl); if (dump_file) { fprintf (dump_file, "Read modref for %s\n", @@ -3711,7 +3757,7 @@ update_signature (struct cgraph_node *node) r_lto->dump (dump_file); } if (r) - r->finalize (); + r->finalize (node->decl); return; } @@ -4917,7 +4963,7 @@ pass_ipa_modref::execute (function *) for (struct cgraph_node *cur = component_node; cur; cur = ((struct ipa_dfs_info *) cur->aux)->next_cycle) if (modref_summary *sum = optimization_summaries->get (cur)) - sum->finalize (); + sum->finalize (cur->decl); if (dump_file) modref_propagate_dump_scc (component_node); } -- cgit v1.1