From 47a1ae3c6a27bfd5875d70860d72ea31d4c98cc7 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Sun, 25 Mar 2012 15:28:32 +0200 Subject: [PATCH] re PR middle-end/51663 (Desirable/undesirable elimination of unused variables & functions at -O0, -O0 -flto and -O0 -fwhole-program) PR lto/51663 * varpool.c (varpool_finalize_decl): Handle toplevel_reorder here. (decide_is_variable_needed): Do not handle toplevel reorder here. * cgraph.h (varpool_can_remove_if_no_refs): Likewise. * ipa.c (cgraph_remove_unreachable_nodes): Remove unreachable vars even at -O0. From-SVN: r185777 --- gcc/ChangeLog | 9 +++++++++ gcc/cgraph.h | 2 -- gcc/ipa.c | 9 ++++----- gcc/varpool.c | 10 +++++----- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 998162247313..0db91475709d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2012-03-24 Jan Hubicka + + PR lto/51663 + * varpool.c (varpool_finalize_decl): Handle toplevel_reorder here. + (decide_is_variable_needed): Do not handle toplevel reorder here. + * cgraph.h (varpool_can_remove_if_no_refs): Likewise. + * ipa.c (cgraph_remove_unreachable_nodes): Remove unreachable vars + even at -O0. + 2012-03-24 Eric Botcazou * expr.c (optimize_bitfield_assignment_op) : Use str_mode diff --git a/gcc/cgraph.h b/gcc/cgraph.h index db4bcea1fc43..93efd94d9ba6 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -947,8 +947,6 @@ static inline bool varpool_can_remove_if_no_refs (struct varpool_node *node) { return (!node->force_output && !node->used_from_other_partition - && (flag_toplevel_reorder || DECL_COMDAT (node->decl) - || DECL_ARTIFICIAL (node->decl)) && (DECL_COMDAT (node->decl) || !node->externally_visible)); } diff --git a/gcc/ipa.c b/gcc/ipa.c index 388291a3d923..88dd9072c0c0 100644 --- a/gcc/ipa.c +++ b/gcc/ipa.c @@ -419,11 +419,6 @@ cgraph_remove_unreachable_nodes (bool before_inlining_p, FILE *file) if (file) fprintf (file, "\n"); - /* We must release unused extern inlines or sanity checking will fail. Rest of transformations - are undesirable at -O0 since we do not want to remove anything. */ - if (!optimize) - return changed; - if (file) fprintf (file, "Reclaiming variables:"); for (vnode = varpool_nodes; vnode; vnode = vnext) @@ -463,6 +458,10 @@ cgraph_remove_unreachable_nodes (bool before_inlining_p, FILE *file) if (file) fprintf (file, "\n"); + /* Rest of transformations are undesirable at -O0. */ + if (!optimize) + return changed; + #ifdef ENABLE_CHECKING verify_cgraph (); #endif diff --git a/gcc/varpool.c b/gcc/varpool.c index c2d88c3bd761..e064f7bd6485 100644 --- a/gcc/varpool.c +++ b/gcc/varpool.c @@ -334,10 +334,6 @@ decide_is_variable_needed (struct varpool_node *node, tree decl) && !DECL_EXTERNAL (decl)) return true; - /* When not reordering top level variables, we have to assume that - we are going to keep everything. */ - if (!flag_toplevel_reorder) - return true; return false; } @@ -405,7 +401,11 @@ varpool_finalize_decl (tree decl) if (node->needed) varpool_enqueue_needed_node (node); node->finalized = true; - if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl)) + if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl) + /* Traditionally we do not eliminate static variables when not + optimizing and when not doing toplevel reoder. */ + || (!flag_toplevel_reorder && !DECL_COMDAT (node->decl) + && !DECL_ARTIFICIAL (node->decl))) node->force_output = true; if (decide_is_variable_needed (node, decl))