Commit dea91a66 by Jan Hubicka Committed by Jan Hubicka

re PR ipa/61602 (ICE in lto1 on x86_64-linux-gnu in ipa_single_use, at ipa.c:1257)


	PR ipa/61602
	* gcc.dg/torture/pr61602.c: New testcase.

	* cgraph.h (ipa_discover_readonly_nonaddressable_vars): Return bool.
	* ipa.c (set_writeonly_bit): Track if reference was removed.
	(ipa_discover_readonly_nonaddressable_vars): Return true if any
	references was removed.
	* ipa-reference.c (propagate): Return TODO_remove_functions if
	reference was removed.

From-SVN: r218731
parent f1ced6f5
...@@ -2188,7 +2188,7 @@ void record_references_in_initializer (tree, bool); ...@@ -2188,7 +2188,7 @@ void record_references_in_initializer (tree, bool);
/* In ipa.c */ /* In ipa.c */
void cgraph_build_static_cdtor (char which, tree body, int priority); void cgraph_build_static_cdtor (char which, tree body, int priority);
void ipa_discover_readonly_nonaddressable_vars (void); bool ipa_discover_readonly_nonaddressable_vars (void);
/* In varpool.c */ /* In varpool.c */
tree ctor_for_folding (tree); tree ctor_for_folding (tree);
......
...@@ -676,11 +676,12 @@ propagate (void) ...@@ -676,11 +676,12 @@ propagate (void)
XCNEWVEC (struct cgraph_node *, symtab->cgraph_count); XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
int order_pos; int order_pos;
int i; int i;
bool remove_p;
if (dump_file) if (dump_file)
cgraph_node::dump_cgraph (dump_file); cgraph_node::dump_cgraph (dump_file);
ipa_discover_readonly_nonaddressable_vars (); remove_p = ipa_discover_readonly_nonaddressable_vars ();
generate_summary (); generate_summary ();
/* Propagate the local information through the call graph to produce /* Propagate the local information through the call graph to produce
...@@ -867,7 +868,7 @@ propagate (void) ...@@ -867,7 +868,7 @@ propagate (void)
if (dump_file) if (dump_file)
splay_tree_delete (reference_vars_to_consider); splay_tree_delete (reference_vars_to_consider);
reference_vars_to_consider = NULL; reference_vars_to_consider = NULL;
return 0; return remove_p ? TODO_remove_functions : 0;
} }
/* Return true if we need to write summary of NODE. */ /* Return true if we need to write summary of NODE. */
......
...@@ -714,14 +714,18 @@ set_readonly_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) ...@@ -714,14 +714,18 @@ set_readonly_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED)
/* Set writeonly bit and clear the initalizer, since it will not be needed. */ /* Set writeonly bit and clear the initalizer, since it will not be needed. */
bool bool
set_writeonly_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) set_writeonly_bit (varpool_node *vnode, void *data)
{ {
vnode->writeonly = true; vnode->writeonly = true;
if (optimize) if (optimize)
{ {
DECL_INITIAL (vnode->decl) = NULL; DECL_INITIAL (vnode->decl) = NULL;
if (!vnode->alias) if (!vnode->alias)
vnode->remove_all_references (); {
if (vnode->num_references ())
*(bool *)data = true;
vnode->remove_all_references ();
}
} }
return false; return false;
} }
...@@ -739,15 +743,18 @@ clear_addressable_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED) ...@@ -739,15 +743,18 @@ clear_addressable_bit (varpool_node *vnode, void *data ATTRIBUTE_UNUSED)
/* Discover variables that have no longer address taken or that are read only /* Discover variables that have no longer address taken or that are read only
and update their flags. and update their flags.
Return true when unreachable symbol removan should be done.
FIXME: This can not be done in between gimplify and omp_expand since FIXME: This can not be done in between gimplify and omp_expand since
readonly flag plays role on what is shared and what is not. Currently we do readonly flag plays role on what is shared and what is not. Currently we do
this transformation as part of whole program visibility and re-do at this transformation as part of whole program visibility and re-do at
ipa-reference pass (to take into account clonning), but it would ipa-reference pass (to take into account clonning), but it would
make sense to do it before early optimizations. */ make sense to do it before early optimizations. */
void bool
ipa_discover_readonly_nonaddressable_vars (void) ipa_discover_readonly_nonaddressable_vars (void)
{ {
bool remove_p = false;
varpool_node *vnode; varpool_node *vnode;
if (dump_file) if (dump_file)
fprintf (dump_file, "Clearing variable flags:"); fprintf (dump_file, "Clearing variable flags:");
...@@ -762,14 +769,16 @@ ipa_discover_readonly_nonaddressable_vars (void) ...@@ -762,14 +769,16 @@ ipa_discover_readonly_nonaddressable_vars (void)
bool read = false; bool read = false;
bool explicit_refs = true; bool explicit_refs = true;
process_references (vnode, &written, &address_taken, &read, &explicit_refs); process_references (vnode, &written, &address_taken, &read,
&explicit_refs);
if (!explicit_refs) if (!explicit_refs)
continue; continue;
if (!address_taken) if (!address_taken)
{ {
if (TREE_ADDRESSABLE (vnode->decl) && dump_file) if (TREE_ADDRESSABLE (vnode->decl) && dump_file)
fprintf (dump_file, " %s (non-addressable)", vnode->name ()); fprintf (dump_file, " %s (non-addressable)", vnode->name ());
vnode->call_for_node_and_aliases (clear_addressable_bit, NULL, true); vnode->call_for_node_and_aliases (clear_addressable_bit, NULL,
true);
} }
if (!address_taken && !written if (!address_taken && !written
/* Making variable in explicit section readonly can cause section /* Making variable in explicit section readonly can cause section
...@@ -785,11 +794,13 @@ ipa_discover_readonly_nonaddressable_vars (void) ...@@ -785,11 +794,13 @@ ipa_discover_readonly_nonaddressable_vars (void)
{ {
if (dump_file) if (dump_file)
fprintf (dump_file, " %s (write-only)", vnode->name ()); fprintf (dump_file, " %s (write-only)", vnode->name ());
vnode->call_for_node_and_aliases (set_writeonly_bit, NULL, true); vnode->call_for_node_and_aliases (set_writeonly_bit, &remove_p,
true);
} }
} }
if (dump_file) if (dump_file)
fprintf (dump_file, "\n"); fprintf (dump_file, "\n");
return remove_p;
} }
/* Free inline summary. */ /* Free inline summary. */
......
2014-12-14 Jan Hubicka <hubicka@ucw.cz>
PR ipa/61602
* gcc.dg/torture/pr61602.c: New testcase.
2014-12-14 Jan Hubicka <hubicka@ucw.cz> 2014-12-14 Jan Hubicka <hubicka@ucw.cz>
PR ipa/61558 PR ipa/61558
......
int a;
int *b = &a, **c = &b;
int
main ()
{
int **d = &b;
*d = 0;
}
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