From ed97ddc649f7edc10e75e05c92cf49fdfbdd6150 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Sat, 15 Mar 2008 14:34:18 +0000 Subject: tree-ssa-ccp.c (get_symbol_constant_value): Export. 2008-03-15 Richard Guenther * tree-ssa-ccp.c (get_symbol_constant_value): Export. (fold_const_aggregate_ref): Likewise. (get_value): Return NULL if we don't have any values. (ccp_finalize): Set const_val to NULL after freeing it. * tree-flow.h (get_symbol_constant_value): Declare. (fold_const_aggregate_ref): Likewise. * tree-ssa-sccvn.c (try_to_simplify): Use them. * gcc.dg/pr23911.c: Adjust testcase. * gcc.dg/tree-ssa/pr14841.c: Likewise. * gcc.dg/tree-ssa/20030922-2.c: Likewise. From-SVN: r133251 --- gcc/ChangeLog | 10 +++++ gcc/testsuite/ChangeLog | 6 +++ gcc/testsuite/gcc.dg/pr23911.c | 13 +++--- gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c | 4 +- gcc/testsuite/gcc.dg/tree-ssa/pr14841.c | 8 ++-- gcc/tree-flow.h | 2 + gcc/tree-ssa-ccp.c | 20 +++++---- gcc/tree-ssa-sccvn.c | 70 +++++++++++++++--------------- 8 files changed, 76 insertions(+), 57 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b0e25a4..ba568d8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,15 @@ 2008-03-15 Richard Guenther + * tree-ssa-ccp.c (get_symbol_constant_value): Export. + (fold_const_aggregate_ref): Likewise. + (get_value): Return NULL if we don't have any values. + (ccp_finalize): Set const_val to NULL after freeing it. + * tree-flow.h (get_symbol_constant_value): Declare. + (fold_const_aggregate_ref): Likewise. + * tree-ssa-sccvn.c (try_to_simplify): Use them. + +2008-03-15 Richard Guenther + PR middle-end/35593 * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Make sure to not produce negative array indices if not allowed. Add diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f453ce1..48445d9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2008-03-15 Richard Guenther + * gcc.dg/pr23911.c: Adjust testcase. + * gcc.dg/tree-ssa/pr14841.c: Likewise. + * gcc.dg/tree-ssa/20030922-2.c: Likewise. + +2008-03-15 Richard Guenther + PR middle-end/35593 * g++.dg/warn/Warray-bounds-3.C: New testcase. diff --git a/gcc/testsuite/gcc.dg/pr23911.c b/gcc/testsuite/gcc.dg/pr23911.c index 9c8fad34..b77dbaa 100644 --- a/gcc/testsuite/gcc.dg/pr23911.c +++ b/gcc/testsuite/gcc.dg/pr23911.c @@ -1,7 +1,7 @@ /* This was a missed optimization in tree constant propagation that CSE would catch later on. */ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-store_ccp" } */ +/* { dg-options "-O -fdump-tree-dce2" } */ double _Complex *a; static const double _Complex b[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -14,9 +14,8 @@ test (void) return; } -/* After store_ccp, there should not be any assignments from real or - imaginary parts anymore. The constants should be loaded from b and - propagated into the elements of a. */ -/* { dg-final { scan-tree-dump-times "= CR" 0 "store_ccp" } } */ -/* { dg-final { scan-tree-dump-times "= CI" 0 "store_ccp" } } */ -/* { dg-final { cleanup-tree-dump "store_ccp" } } */ +/* After DCE2 which runs after FRE, the expressions should be fully + constant folded. There should be no loads from b left. */ +/* { dg-final { scan-tree-dump-times "__complex__ \\\(1.0e\\\+0, 0.0\\\)" 2 "dce2" } } */ +/* { dg-final { scan-tree-dump-times "= b" 0 "dce2" } } */ +/* { dg-final { cleanup-tree-dump "dce2" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c b/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c index 8843112..9a787bd 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c @@ -7,8 +7,8 @@ struct rtx_def { int bb; }; -static int *block_to_bb; -static int target_bb; +int *block_to_bb; +int target_bb; int rgn_rank (rtx insn1, rtx insn2) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr14841.c b/gcc/testsuite/gcc.dg/tree-ssa/pr14841.c index 05ceeb2..cc6e015 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr14841.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr14841.c @@ -2,8 +2,8 @@ Make sure that we can fold a possible nested reference into a constant aggregate. */ -/* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-store_ccp-details" } */ +/* { dg-do link } */ +/* { dg-options "-O" } */ struct car { int speed; @@ -25,5 +25,5 @@ foo (void) link_error (); } -/* { dg-final { scan-tree-dump-times "Folded statement: if " 1 "store_ccp"} } */ -/* { dg-final { cleanup-tree-dump "store_ccp" } } */ +int main () { return 0; } + diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h index 274e740..fddd1dc 100644 --- a/gcc/tree-flow.h +++ b/gcc/tree-flow.h @@ -940,6 +940,8 @@ void set_current_def (tree, tree); /* In tree-ssa-ccp.c */ bool fold_stmt (tree *); bool fold_stmt_inplace (tree); +tree get_symbol_constant_value (tree); +tree fold_const_aggregate_ref (tree); tree widen_bitfield (tree, tree, tree); /* In tree-vrp.c */ diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 8b8a902..a1eaab2 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -295,23 +295,22 @@ ccp_decl_initial_min_invariant (tree t) /* If SYM is a constant variable with known value, return the value. NULL_TREE is returned otherwise. */ -static tree +tree get_symbol_constant_value (tree sym) { if (TREE_STATIC (sym) && TREE_READONLY (sym) - && !MTAG_P (sym) - /* Check if a read-only definition may be overridden at - link and run time. */ - && targetm.binds_local_p (sym)) + && !MTAG_P (sym)) { tree val = DECL_INITIAL (sym); if (val && ccp_decl_initial_min_invariant (val)) return val; /* Variables declared 'const' without an initializer - have zero as the intializer. */ + have zero as the intializer if they may not be + overridden at link or run time. */ if (!val + && targetm.binds_local_p (sym) && (INTEGRAL_TYPE_P (TREE_TYPE (sym)) || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym)))) return fold_convert (TREE_TYPE (sym), integer_zero_node); @@ -406,8 +405,12 @@ get_default_value (tree var) static inline prop_value_t * get_value (tree var) { - prop_value_t *val = &const_val[SSA_NAME_VERSION (var)]; + prop_value_t *val; + if (const_val == NULL) + return NULL; + + val = &const_val[SSA_NAME_VERSION (var)]; if (val->lattice_val == UNINITIALIZED) *val = get_default_value (var); @@ -722,6 +725,7 @@ ccp_finalize (void) bool something_changed = substitute_and_fold (const_val, false); free (const_val); + const_val = NULL; return something_changed;; } @@ -1026,7 +1030,7 @@ ccp_fold (tree stmt) ARRAY_REF or COMPONENT_REF into constant aggregates. Return NULL_TREE otherwise. */ -static tree +tree fold_const_aggregate_ref (tree t) { prop_value_t *value; diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 3b42c24..b10d3e3 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1597,48 +1597,46 @@ simplify_unary_expression (tree rhs) static tree try_to_simplify (tree stmt, tree rhs) { + tree tem; + /* For stores we can end up simplifying a SSA_NAME rhs. Just return in this case, there is no point in doing extra work. */ if (TREE_CODE (rhs) == SSA_NAME) return rhs; - else + + switch (TREE_CODE_CLASS (TREE_CODE (rhs))) { - switch (TREE_CODE_CLASS (TREE_CODE (rhs))) - { - /* For references, see if we find a result for the lookup, - and use it if we do. */ - case tcc_declaration: - /* Pull out any truly constant values. */ - if (TREE_READONLY (rhs) - && TREE_STATIC (rhs) - && DECL_INITIAL (rhs) - && valid_gimple_expression_p (DECL_INITIAL (rhs))) - return DECL_INITIAL (rhs); - - /* Fallthrough. */ - case tcc_reference: - /* Do not do full-blown reference lookup here. - ??? But like for tcc_declaration, we should simplify - from constant initializers. */ - - /* Fallthrough for some codes that can operate on registers. */ - if (!(TREE_CODE (rhs) == REALPART_EXPR - || TREE_CODE (rhs) == IMAGPART_EXPR - || TREE_CODE (rhs) == VIEW_CONVERT_EXPR)) - break; - /* We could do a little more with unary ops, if they expand - into binary ops, but it's debatable whether it is worth it. */ - case tcc_unary: - return simplify_unary_expression (rhs); - break; - case tcc_comparison: - case tcc_binary: - return simplify_binary_expression (stmt, rhs); - break; - default: - break; - } + case tcc_declaration: + tem = get_symbol_constant_value (rhs); + if (tem) + return tem; + break; + + case tcc_reference: + /* Do not do full-blown reference lookup here, but simplify + reads from constant aggregates. */ + tem = fold_const_aggregate_ref (rhs); + if (tem) + return tem; + + /* Fallthrough for some codes that can operate on registers. */ + if (!(TREE_CODE (rhs) == REALPART_EXPR + || TREE_CODE (rhs) == IMAGPART_EXPR + || TREE_CODE (rhs) == VIEW_CONVERT_EXPR)) + break; + /* We could do a little more with unary ops, if they expand + into binary ops, but it's debatable whether it is worth it. */ + case tcc_unary: + return simplify_unary_expression (rhs); + break; + case tcc_comparison: + case tcc_binary: + return simplify_binary_expression (stmt, rhs); + break; + default: + break; } + return rhs; } -- cgit v1.1