aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2010-09-04 19:36:49 +0200
committerJan Hubicka <hubicka@gcc.gnu.org>2010-09-04 17:36:49 +0000
commit17f39a395648213a0c6014e84ff34f3ff565a10b (patch)
tree57771775ce3d663de352f64104a3e0370a61a56f /gcc/gimple-fold.c
parent5f7ae6b656d4468b1f2ebf3f773e494c7d147624 (diff)
downloadgcc-17f39a395648213a0c6014e84ff34f3ff565a10b.zip
gcc-17f39a395648213a0c6014e84ff34f3ff565a10b.tar.gz
gcc-17f39a395648213a0c6014e84ff34f3ff565a10b.tar.bz2
foldconst-2.c: New testcase.
* gcc.dg/tree-ssa/foldconst-2.c: New testcase. * gcc.dg/tree-ssa/foldconst-3.c: New testcase. * gimple-fold.c (maybe_fold_reference): Use fold_const_aggregate_ref. * tree-ssa-ccp.c (fold_const_aggregate_ref): Use fold_read_from_constant_string. * gimple.h (canonicalize_constructor_val): Declare. * gimple-fold.c (canonicalize_constructor_val): New function. (get_symbol_constant_value):Use it. * tree-ssa-ccp.c (fold_const_aggregate_ref): Likewise. From-SVN: r163861
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 033023a..2b40ee6 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -31,6 +31,30 @@ along with GCC; see the file COPYING3. If not see
#include "tree-ssa-propagate.h"
#include "target.h"
+/* CVAL is value taken from DECL_INITIAL of variable. Try to transorm it into
+ acceptable form for is_gimple_min_invariant. */
+
+tree
+canonicalize_constructor_val (tree cval)
+{
+ STRIP_NOPS (cval);
+ if (TREE_CODE (cval) == POINTER_PLUS_EXPR)
+ {
+ tree t = maybe_fold_offset_to_address (EXPR_LOCATION (cval),
+ TREE_OPERAND (cval, 0),
+ TREE_OPERAND (cval, 1),
+ TREE_TYPE (cval));
+ if (t)
+ cval = t;
+ }
+ if (TREE_CODE (cval) == ADDR_EXPR)
+ {
+ tree base = get_base_address (TREE_OPERAND (cval, 0));
+ if (base && TREE_CODE (base) == VAR_DECL)
+ add_referenced_var (base);
+ }
+ return cval;
+}
/* If SYM is a constant variable with known value, return the value.
NULL_TREE is returned otherwise. */
@@ -45,21 +69,9 @@ get_symbol_constant_value (tree sym)
tree val = DECL_INITIAL (sym);
if (val)
{
- STRIP_NOPS (val);
+ val = canonicalize_constructor_val (val);
if (is_gimple_min_invariant (val))
- {
- if (TREE_CODE (val) == ADDR_EXPR)
- {
- tree base = get_base_address (TREE_OPERAND (val, 0));
- if (base && TREE_CODE (base) == VAR_DECL)
- {
- TREE_ADDRESSABLE (base) = 1;
- if (gimple_referenced_vars (cfun))
- add_referenced_var (base);
- }
- }
- return val;
- }
+ return val;
}
/* Variables declared 'const' without an initializer
have zero as the initializer if they may not be
@@ -462,14 +474,11 @@ static tree
maybe_fold_reference (tree expr, bool is_lhs)
{
tree *t = &expr;
+ tree result;
- if (TREE_CODE (expr) == ARRAY_REF
- && !is_lhs)
- {
- tree tem = fold_read_from_constant_string (expr);
- if (tem)
- return tem;
- }
+ if (!is_lhs
+ && (result = fold_const_aggregate_ref (expr)))
+ return result;
/* ??? We might want to open-code the relevant remaining cases
to avoid using the generic fold. */