diff options
author | hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-20 15:48:42 +0000 |
---|---|---|
committer | hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-20 15:48:42 +0000 |
commit | 7ae8b539ca01417750951904f33f9ad7846ba3aa (patch) | |
tree | 5dc2da773507a107b478346e98a80752893d9599 /gcc/varpool.c | |
parent | 181ab2776c9d3a2e81b479fee68be22ff63ec272 (diff) | |
download | gcc-7ae8b539ca01417750951904f33f9ad7846ba3aa.tar.gz |
PR tree-optimize/45605
* cgraph.h (const_value_known_p): Declare.
(varpool_decide_const_value_known): Remove.
* tree-ssa-ccp.c (get_base_constructor): Use it.
* lto-cgraph.c (compute_ltrans_boundary): Likewise.
* expr.c (string_constant): Likewise.
* tree-ssa-loop-ivcanon.c (constant_after_peeling): Likewise.
* ipa.c (ipa_discover_readonly_nonaddressable_var,
function_and_variable_visibility): Likewise.
* gimplify.c (gimplify_call_expr): Likewise.
* gimple-fold.c (get_symbol_constant_value): Likewise.
* varpool.c (varpool_decide_const_value_known): Replace by...
(const_value_known_p): ... this one; handle other kinds of DECLs
too and work for automatic vars.
(varpool_finalize_decl): Use const_value_known_p.
* lto.c (lto_promote_cross_file_statics): Use const_value_known_p.
* g++.dg/tree-ssa/pr45605.C: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164438 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/varpool.c')
-rw-r--r-- | gcc/varpool.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/gcc/varpool.c b/gcc/varpool.c index 2b0809456ea..3ce3bac8ded 100644 --- a/gcc/varpool.c +++ b/gcc/varpool.c @@ -359,21 +359,42 @@ decide_is_variable_needed (struct varpool_node *node, tree decl) return true; } -/* Return if NODE is constant and its initial value is known (so we can do - constant folding). The decision depends on whole program decisions - and can not be recomputed at ltrans stage for variables from other - partitions. For this reason the new value should be always combined - with the previous knowledge. */ +/* Return if DECL is constant and its initial value is known (so we can do + constant folding using DECL_INITIAL (decl)). */ bool -varpool_decide_const_value_known (struct varpool_node *node) +const_value_known_p (tree decl) { - tree decl = node->decl; + struct varpool_node *vnode; + + if (TREE_CODE (decl) == PARM_DECL + || TREE_CODE (decl) == RESULT_DECL) + return false; + + if (TREE_CODE (decl) == CONST_DECL + || DECL_IN_CONSTANT_POOL (decl)) + return true; - gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl)); gcc_assert (TREE_CODE (decl) == VAR_DECL); + if (!TREE_READONLY (decl)) return false; + + /* Gimplifier takes away constructors of local vars */ + if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) + return DECL_INITIAL (decl) != NULL; + + gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl)); + + /* In WHOPR mode we can put variable into one partition + and make it external in the other partition. In this + case we still know the value, but it can't be determined + from DECL flags. For this reason we keep const_value_known + flag in varpool nodes. */ + if ((vnode = varpool_get_node (decl)) + && vnode->const_value_known) + return true; + /* Variables declared 'const' without an initializer have zero as the initializer if they may not be overridden at link or run time. */ @@ -423,7 +444,7 @@ varpool_finalize_decl (tree decl) there. */ else if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl)) varpool_mark_needed_node (node); - node->const_value_known |= varpool_decide_const_value_known (node); + node->const_value_known |= const_value_known_p (node->decl); if (cgraph_global_info_ready) varpool_assemble_pending_decls (); } |