From 37074a02aee862ae15867e40aa5a12db616657b6 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 9 Dec 2015 08:34:16 +0100 Subject: [PATCH] re PR lto/61886 (LTO breaks fread with _FORTIFY_SOURCE=2) PR ipa/61886 PR middle-end/25140 * ipa-reference.c (is_improper): Break out from ... (is_proper_for_analysis): ... here; fix WRT aliases. (analyze_function, generate_summary, ipa_reference_write_optimization_summary, ipa_reference_read_optimization_summary): Use ipa_reference_var_uid. * ipa-refrence.h (ipa_reference_var_uid): New inline. * tree-ssa-alias.c (ref_maybe_used_by_call_p_1, call_may_clobber_ref_p_1): Use ipa_reference_var_uid. * gcc.c-torture/execute/alias-3.c: New testcase. From-SVN: r231442 --- gcc/ipa-reference.c | 73 ++++++++++++------- gcc/ipa-reference.h | 6 ++ gcc/testsuite/ChangeLog | 6 ++ gcc/testsuite/gcc.c-torture/execute/alias-3.c | 17 +++++ gcc/tree-ssa-alias.c | 32 +++++--- 5 files changed, 96 insertions(+), 38 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/alias-3.c diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index 88c49975005..be98cdc5893 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -167,8 +167,8 @@ set_reference_optimization_summary (struct cgraph_node *node, ipa_reference_opt_sum_vector[node->uid] = info; } -/* Return a bitmap indexed by DECL_UID for the static variables that - are *not* read during the execution of the function FN. Returns +/* Return a bitmap indexed by ipa_reference_var_uid for the static variables + that are *not* read during the execution of the function FN. Returns NULL if no data is available. */ bitmap @@ -187,8 +187,8 @@ ipa_reference_get_not_read_global (struct cgraph_node *fn) return NULL; } -/* Return a bitmap indexed by DECL_UID for the static variables that - are *not* written during the execution of the function FN. Note +/* Return a bitmap indexed by ipa_reference_var_uid for the static variables + that are *not* written during the execution of the function FN. Note that variables written may or may not be read during the function call. Returns NULL if no data is available. */ @@ -207,40 +207,51 @@ ipa_reference_get_not_written_global (struct cgraph_node *fn) else return NULL; } - -/* Return true if the variable T is the right kind of static variable to - perform compilation unit scope escape analysis. */ -static inline bool -is_proper_for_analysis (tree t) +/* Hepler for is_proper_for_analysis. */ +static bool +is_improper (symtab_node *n, void *v ATTRIBUTE_UNUSED) { + tree t = n->decl; /* If the variable has the "used" attribute, treat it as if it had a been touched by the devil. */ if (DECL_PRESERVE_P (t)) - return false; + return true; /* Do not want to do anything with volatile except mark any function that uses one to be not const or pure. */ if (TREE_THIS_VOLATILE (t)) - return false; + return true; /* We do not need to analyze readonly vars, we already know they do not alias. */ if (TREE_READONLY (t)) - return false; + return true; /* We can not track variables with address taken. */ if (TREE_ADDRESSABLE (t)) - return false; + return true; - /* TODO: We could track public variables that are not addressable, but currently - frontends don't give us those. */ + /* TODO: We could track public variables that are not addressable, but + currently frontends don't give us those. */ if (TREE_PUBLIC (t)) + return true; + + return false; +} + +/* Return true if the variable T is the right kind of static variable to + perform compilation unit scope escape analysis. */ + +static inline bool +is_proper_for_analysis (tree t) +{ + if (bitmap_bit_p (ignore_module_statics, ipa_reference_var_uid (t))) return false; - /* TODO: Check aliases. */ - if (bitmap_bit_p (ignore_module_statics, DECL_UID (t))) + if (symtab_node::get (t) + ->call_for_symbol_and_aliases (is_improper, NULL, true)) return false; return true; @@ -452,21 +463,22 @@ analyze_function (struct cgraph_node *fn) /* This is a variable we care about. Check if we have seen it before, and if not add it the set of variables we care about. */ if (all_module_statics - && bitmap_set_bit (all_module_statics, DECL_UID (var))) + && bitmap_set_bit (all_module_statics, ipa_reference_var_uid (var))) { if (dump_file) splay_tree_insert (reference_vars_to_consider, - DECL_UID (var), (splay_tree_value)var); + ipa_reference_var_uid (var), + (splay_tree_value)var); } switch (ref->use) { case IPA_REF_LOAD: - bitmap_set_bit (local->statics_read, DECL_UID (var)); + bitmap_set_bit (local->statics_read, ipa_reference_var_uid (var)); break; case IPA_REF_STORE: if (ref->cannot_lead_to_return ()) break; - bitmap_set_bit (local->statics_written, DECL_UID (var)); + bitmap_set_bit (local->statics_written, ipa_reference_var_uid (var)); break; case IPA_REF_ADDR: break; @@ -547,7 +559,7 @@ generate_summary (void) var = ref->referred->decl; if (!is_proper_for_analysis (var)) continue; - bitmap_set_bit (ignore_module_statics, DECL_UID (var)); + bitmap_set_bit (ignore_module_statics, ipa_reference_var_uid (var)); } } FOR_EACH_DEFINED_FUNCTION (node) @@ -975,13 +987,15 @@ ipa_reference_write_optimization_summary (void) symtab_node *snode = lto_symtab_encoder_deref (encoder, i); varpool_node *vnode = dyn_cast (snode); if (vnode - && bitmap_bit_p (all_module_statics, DECL_UID (vnode->decl)) + && bitmap_bit_p (all_module_statics, + ipa_reference_var_uid (vnode->decl)) && referenced_from_this_partition_p (vnode, encoder)) { tree decl = vnode->decl; - bitmap_set_bit (ltrans_statics, DECL_UID (decl)); + bitmap_set_bit (ltrans_statics, ipa_reference_var_uid (decl)); splay_tree_insert (reference_vars_to_consider, - DECL_UID (decl), (splay_tree_value)decl); + ipa_reference_var_uid (decl), + (splay_tree_value)decl); ltrans_statics_bitcount ++; } } @@ -1067,7 +1081,8 @@ ipa_reference_read_optimization_summary (void) unsigned int var_index = streamer_read_uhwi (ib); tree v_decl = lto_file_decl_data_get_var_decl (file_data, var_index); - bitmap_set_bit (all_module_statics, DECL_UID (v_decl)); + bitmap_set_bit (all_module_statics, + ipa_reference_var_uid (v_decl)); if (dump_file) fprintf (dump_file, " %s", fndecl_name (v_decl)); } @@ -1107,7 +1122,8 @@ ipa_reference_read_optimization_summary (void) unsigned int var_index = streamer_read_uhwi (ib); tree v_decl = lto_file_decl_data_get_var_decl (file_data, var_index); - bitmap_set_bit (info->statics_not_read, DECL_UID (v_decl)); + bitmap_set_bit (info->statics_not_read, + ipa_reference_var_uid (v_decl)); if (dump_file) fprintf (dump_file, " %s", fndecl_name (v_decl)); } @@ -1129,7 +1145,8 @@ ipa_reference_read_optimization_summary (void) unsigned int var_index = streamer_read_uhwi (ib); tree v_decl = lto_file_decl_data_get_var_decl (file_data, var_index); - bitmap_set_bit (info->statics_not_written, DECL_UID (v_decl)); + bitmap_set_bit (info->statics_not_written, + ipa_reference_var_uid (v_decl)); if (dump_file) fprintf (dump_file, " %s", fndecl_name (v_decl)); } diff --git a/gcc/ipa-reference.h b/gcc/ipa-reference.h index 137d7e8a62d..6e9d6e70017 100644 --- a/gcc/ipa-reference.h +++ b/gcc/ipa-reference.h @@ -26,5 +26,11 @@ bitmap ipa_reference_get_not_read_global (struct cgraph_node *fn); bitmap ipa_reference_get_not_written_global (struct cgraph_node *fn); void ipa_reference_c_finalize (void); +inline int +ipa_reference_var_uid (tree t) +{ + return DECL_UID (symtab_node::get (t)->ultimate_alias_target (NULL)->decl); +} + #endif /* GCC_IPA_REFERENCE_H */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5cefc07641d..68d9a2dcff4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-12-08 Jan Hubicka + + PR ipa/61886 + PR middle-end/25140 + * gcc.c-torture/execute/alias-3.c: New testcase. + 2015-12-08 Martin Sebor PR c++/68711 diff --git a/gcc/testsuite/gcc.c-torture/execute/alias-3.c b/gcc/testsuite/gcc.c-torture/execute/alias-3.c new file mode 100644 index 00000000000..9bae2689271 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/alias-3.c @@ -0,0 +1,17 @@ +/* { dg-require-alias "" } */ +static int a=0; +extern int b __attribute__ ((alias("a"))); +__attribute__ ((noinline)) +static inc() +{ + b++; +} +int +main() +{ + a=0; + inc (); + if (a!=1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index e1d9cda8fe8..c859e3fcedf 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -1739,15 +1739,21 @@ ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref) && TREE_STATIC (base)) { struct cgraph_node *node = cgraph_node::get (callee); - bitmap not_read; /* FIXME: Callee can be an OMP builtin that does not have a call graph node yet. We should enforce that there are nodes for all decls in the IL and remove this check instead. */ - if (node - && (not_read = ipa_reference_get_not_read_global (node)) - && bitmap_bit_p (not_read, DECL_UID (base))) - goto process_args; + if (node) + { + enum availability avail; + bitmap not_read; + + node = node->ultimate_alias_target (&avail); + if (avail >= AVAIL_AVAILABLE + && (not_read = ipa_reference_get_not_read_global (node)) + && bitmap_bit_p (not_read, ipa_reference_var_uid (base))) + goto process_args; + } } /* Check if the base variable is call-used. */ @@ -2128,12 +2134,18 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref) && TREE_STATIC (base)) { struct cgraph_node *node = cgraph_node::get (callee); - bitmap not_written; - if (node - && (not_written = ipa_reference_get_not_written_global (node)) - && bitmap_bit_p (not_written, DECL_UID (base))) - return false; + if (node) + { + bitmap not_written; + enum availability avail; + + node = node->ultimate_alias_target (&avail); + if (avail >= AVAIL_AVAILABLE + && (not_written = ipa_reference_get_not_written_global (node)) + && bitmap_bit_p (not_written, ipa_reference_var_uid (base))) + return false; + } } /* Check if the base variable is call-clobbered. */ -- 2.30.2