Commit 37074a02 by Jan Hubicka Committed by Jan Hubicka

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
parent 04d2fbcc
...@@ -167,8 +167,8 @@ set_reference_optimization_summary (struct cgraph_node *node, ...@@ -167,8 +167,8 @@ set_reference_optimization_summary (struct cgraph_node *node,
ipa_reference_opt_sum_vector[node->uid] = info; ipa_reference_opt_sum_vector[node->uid] = info;
} }
/* Return a bitmap indexed by DECL_UID for the static variables that /* Return a bitmap indexed by ipa_reference_var_uid for the static variables
are *not* read during the execution of the function FN. Returns that are *not* read during the execution of the function FN. Returns
NULL if no data is available. */ NULL if no data is available. */
bitmap bitmap
...@@ -187,8 +187,8 @@ ipa_reference_get_not_read_global (struct cgraph_node *fn) ...@@ -187,8 +187,8 @@ ipa_reference_get_not_read_global (struct cgraph_node *fn)
return NULL; return NULL;
} }
/* Return a bitmap indexed by DECL_UID for the static variables that /* Return a bitmap indexed by ipa_reference_var_uid for the static variables
are *not* written during the execution of the function FN. Note that are *not* written during the execution of the function FN. Note
that variables written may or may not be read during the function that variables written may or may not be read during the function
call. Returns NULL if no data is available. */ call. Returns NULL if no data is available. */
...@@ -209,38 +209,49 @@ ipa_reference_get_not_written_global (struct cgraph_node *fn) ...@@ -209,38 +209,49 @@ ipa_reference_get_not_written_global (struct cgraph_node *fn)
} }
/* Return true if the variable T is the right kind of static variable to /* Hepler for is_proper_for_analysis. */
perform compilation unit scope escape analysis. */ static bool
is_improper (symtab_node *n, void *v ATTRIBUTE_UNUSED)
static inline bool
is_proper_for_analysis (tree t)
{ {
tree t = n->decl;
/* If the variable has the "used" attribute, treat it as if it had a /* If the variable has the "used" attribute, treat it as if it had a
been touched by the devil. */ been touched by the devil. */
if (DECL_PRESERVE_P (t)) if (DECL_PRESERVE_P (t))
return false; return true;
/* Do not want to do anything with volatile except mark any /* Do not want to do anything with volatile except mark any
function that uses one to be not const or pure. */ function that uses one to be not const or pure. */
if (TREE_THIS_VOLATILE (t)) if (TREE_THIS_VOLATILE (t))
return false; return true;
/* We do not need to analyze readonly vars, we already know they do not /* We do not need to analyze readonly vars, we already know they do not
alias. */ alias. */
if (TREE_READONLY (t)) if (TREE_READONLY (t))
return false; return true;
/* We can not track variables with address taken. */ /* We can not track variables with address taken. */
if (TREE_ADDRESSABLE (t)) if (TREE_ADDRESSABLE (t))
return false; return true;
/* TODO: We could track public variables that are not addressable, but currently /* TODO: We could track public variables that are not addressable, but
frontends don't give us those. */ currently frontends don't give us those. */
if (TREE_PUBLIC (t)) 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; return false;
/* TODO: Check aliases. */ if (symtab_node::get (t)
if (bitmap_bit_p (ignore_module_statics, DECL_UID (t))) ->call_for_symbol_and_aliases (is_improper, NULL, true))
return false; return false;
return true; return true;
...@@ -452,21 +463,22 @@ analyze_function (struct cgraph_node *fn) ...@@ -452,21 +463,22 @@ analyze_function (struct cgraph_node *fn)
/* This is a variable we care about. Check if we have seen it /* 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. */ before, and if not add it the set of variables we care about. */
if (all_module_statics 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) if (dump_file)
splay_tree_insert (reference_vars_to_consider, 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) switch (ref->use)
{ {
case IPA_REF_LOAD: 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; break;
case IPA_REF_STORE: case IPA_REF_STORE:
if (ref->cannot_lead_to_return ()) if (ref->cannot_lead_to_return ())
break; break;
bitmap_set_bit (local->statics_written, DECL_UID (var)); bitmap_set_bit (local->statics_written, ipa_reference_var_uid (var));
break; break;
case IPA_REF_ADDR: case IPA_REF_ADDR:
break; break;
...@@ -547,7 +559,7 @@ generate_summary (void) ...@@ -547,7 +559,7 @@ generate_summary (void)
var = ref->referred->decl; var = ref->referred->decl;
if (!is_proper_for_analysis (var)) if (!is_proper_for_analysis (var))
continue; 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) FOR_EACH_DEFINED_FUNCTION (node)
...@@ -975,13 +987,15 @@ ipa_reference_write_optimization_summary (void) ...@@ -975,13 +987,15 @@ ipa_reference_write_optimization_summary (void)
symtab_node *snode = lto_symtab_encoder_deref (encoder, i); symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
varpool_node *vnode = dyn_cast <varpool_node *> (snode); varpool_node *vnode = dyn_cast <varpool_node *> (snode);
if (vnode 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)) && referenced_from_this_partition_p (vnode, encoder))
{ {
tree decl = vnode->decl; 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, 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 ++; ltrans_statics_bitcount ++;
} }
} }
...@@ -1067,7 +1081,8 @@ ipa_reference_read_optimization_summary (void) ...@@ -1067,7 +1081,8 @@ ipa_reference_read_optimization_summary (void)
unsigned int var_index = streamer_read_uhwi (ib); unsigned int var_index = streamer_read_uhwi (ib);
tree v_decl = lto_file_decl_data_get_var_decl (file_data, tree v_decl = lto_file_decl_data_get_var_decl (file_data,
var_index); 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) if (dump_file)
fprintf (dump_file, " %s", fndecl_name (v_decl)); fprintf (dump_file, " %s", fndecl_name (v_decl));
} }
...@@ -1107,7 +1122,8 @@ ipa_reference_read_optimization_summary (void) ...@@ -1107,7 +1122,8 @@ ipa_reference_read_optimization_summary (void)
unsigned int var_index = streamer_read_uhwi (ib); unsigned int var_index = streamer_read_uhwi (ib);
tree v_decl = lto_file_decl_data_get_var_decl (file_data, tree v_decl = lto_file_decl_data_get_var_decl (file_data,
var_index); 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) if (dump_file)
fprintf (dump_file, " %s", fndecl_name (v_decl)); fprintf (dump_file, " %s", fndecl_name (v_decl));
} }
...@@ -1129,7 +1145,8 @@ ipa_reference_read_optimization_summary (void) ...@@ -1129,7 +1145,8 @@ ipa_reference_read_optimization_summary (void)
unsigned int var_index = streamer_read_uhwi (ib); unsigned int var_index = streamer_read_uhwi (ib);
tree v_decl = lto_file_decl_data_get_var_decl (file_data, tree v_decl = lto_file_decl_data_get_var_decl (file_data,
var_index); 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) if (dump_file)
fprintf (dump_file, " %s", fndecl_name (v_decl)); fprintf (dump_file, " %s", fndecl_name (v_decl));
} }
......
...@@ -26,5 +26,11 @@ bitmap ipa_reference_get_not_read_global (struct cgraph_node *fn); ...@@ -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); bitmap ipa_reference_get_not_written_global (struct cgraph_node *fn);
void ipa_reference_c_finalize (void); 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 */ #endif /* GCC_IPA_REFERENCE_H */
2015-12-08 Jan Hubicka <hubicka@ucw.cz>
PR ipa/61886
PR middle-end/25140
* gcc.c-torture/execute/alias-3.c: New testcase.
2015-12-08 Martin Sebor <msebor@redhat.com> 2015-12-08 Martin Sebor <msebor@redhat.com>
PR c++/68711 PR c++/68711
......
/* { 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;
}
...@@ -1739,16 +1739,22 @@ ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref) ...@@ -1739,16 +1739,22 @@ ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref)
&& TREE_STATIC (base)) && TREE_STATIC (base))
{ {
struct cgraph_node *node = cgraph_node::get (callee); 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 /* 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 node yet. We should enforce that there are nodes for all decls in the
IL and remove this check instead. */ IL and remove this check instead. */
if (node 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)) && (not_read = ipa_reference_get_not_read_global (node))
&& bitmap_bit_p (not_read, DECL_UID (base))) && bitmap_bit_p (not_read, ipa_reference_var_uid (base)))
goto process_args; goto process_args;
} }
}
/* Check if the base variable is call-used. */ /* Check if the base variable is call-used. */
if (DECL_P (base)) if (DECL_P (base))
...@@ -2128,13 +2134,19 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref) ...@@ -2128,13 +2134,19 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref)
&& TREE_STATIC (base)) && TREE_STATIC (base))
{ {
struct cgraph_node *node = cgraph_node::get (callee); struct cgraph_node *node = cgraph_node::get (callee);
if (node)
{
bitmap not_written; bitmap not_written;
enum availability avail;
if (node node = node->ultimate_alias_target (&avail);
if (avail >= AVAIL_AVAILABLE
&& (not_written = ipa_reference_get_not_written_global (node)) && (not_written = ipa_reference_get_not_written_global (node))
&& bitmap_bit_p (not_written, DECL_UID (base))) && bitmap_bit_p (not_written, ipa_reference_var_uid (base)))
return false; return false;
} }
}
/* Check if the base variable is call-clobbered. */ /* Check if the base variable is call-clobbered. */
if (DECL_P (base)) if (DECL_P (base))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment