Commit ed97ddc6 by Richard Guenther Committed by Richard Biener

tree-ssa-ccp.c (get_symbol_constant_value): Export.

2008-03-15  Richard Guenther  <rguenther@suse.de>

	* 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
parent ab551054
2008-03-15 Richard Guenther <rguenther@suse.de> 2008-03-15 Richard Guenther <rguenther@suse.de>
* 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 <rguenther@suse.de>
PR middle-end/35593 PR middle-end/35593
* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Make sure * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Make sure
to not produce negative array indices if not allowed. Add to not produce negative array indices if not allowed. Add
......
2008-03-15 Richard Guenther <rguenther@suse.de> 2008-03-15 Richard Guenther <rguenther@suse.de>
* 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 <rguenther@suse.de>
PR middle-end/35593 PR middle-end/35593
* g++.dg/warn/Warray-bounds-3.C: New testcase. * g++.dg/warn/Warray-bounds-3.C: New testcase.
/* This was a missed optimization in tree constant propagation /* This was a missed optimization in tree constant propagation
that CSE would catch later on. */ that CSE would catch later on. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-store_ccp" } */ /* { dg-options "-O -fdump-tree-dce2" } */
double _Complex *a; double _Complex *a;
static const double _Complex b[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; static const double _Complex b[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
...@@ -14,9 +14,8 @@ test (void) ...@@ -14,9 +14,8 @@ test (void)
return; return;
} }
/* After store_ccp, there should not be any assignments from real or /* After DCE2 which runs after FRE, the expressions should be fully
imaginary parts anymore. The constants should be loaded from b and constant folded. There should be no loads from b left. */
propagated into the elements of a. */ /* { dg-final { scan-tree-dump-times "__complex__ \\\(1.0e\\\+0, 0.0\\\)" 2 "dce2" } } */
/* { dg-final { scan-tree-dump-times "= CR" 0 "store_ccp" } } */ /* { dg-final { scan-tree-dump-times "= b" 0 "dce2" } } */
/* { dg-final { scan-tree-dump-times "= CI" 0 "store_ccp" } } */ /* { dg-final { cleanup-tree-dump "dce2" } } */
/* { dg-final { cleanup-tree-dump "store_ccp" } } */
...@@ -7,8 +7,8 @@ struct rtx_def ...@@ -7,8 +7,8 @@ struct rtx_def
{ {
int bb; int bb;
}; };
static int *block_to_bb; int *block_to_bb;
static int target_bb; int target_bb;
int int
rgn_rank (rtx insn1, rtx insn2) rgn_rank (rtx insn1, rtx insn2)
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
Make sure that we can fold a possible nested reference into a Make sure that we can fold a possible nested reference into a
constant aggregate. */ constant aggregate. */
/* { dg-do compile } */ /* { dg-do link } */
/* { dg-options "-O2 -fdump-tree-store_ccp-details" } */ /* { dg-options "-O" } */
struct car { struct car {
int speed; int speed;
...@@ -25,5 +25,5 @@ foo (void) ...@@ -25,5 +25,5 @@ foo (void)
link_error (); link_error ();
} }
/* { dg-final { scan-tree-dump-times "Folded statement: if " 1 "store_ccp"} } */ int main () { return 0; }
/* { dg-final { cleanup-tree-dump "store_ccp" } } */
...@@ -940,6 +940,8 @@ void set_current_def (tree, tree); ...@@ -940,6 +940,8 @@ void set_current_def (tree, tree);
/* In tree-ssa-ccp.c */ /* In tree-ssa-ccp.c */
bool fold_stmt (tree *); bool fold_stmt (tree *);
bool fold_stmt_inplace (tree); bool fold_stmt_inplace (tree);
tree get_symbol_constant_value (tree);
tree fold_const_aggregate_ref (tree);
tree widen_bitfield (tree, tree, tree); tree widen_bitfield (tree, tree, tree);
/* In tree-vrp.c */ /* In tree-vrp.c */
......
...@@ -295,23 +295,22 @@ ccp_decl_initial_min_invariant (tree t) ...@@ -295,23 +295,22 @@ ccp_decl_initial_min_invariant (tree t)
/* If SYM is a constant variable with known value, return the value. /* If SYM is a constant variable with known value, return the value.
NULL_TREE is returned otherwise. */ NULL_TREE is returned otherwise. */
static tree tree
get_symbol_constant_value (tree sym) get_symbol_constant_value (tree sym)
{ {
if (TREE_STATIC (sym) if (TREE_STATIC (sym)
&& TREE_READONLY (sym) && TREE_READONLY (sym)
&& !MTAG_P (sym) && !MTAG_P (sym))
/* Check if a read-only definition may be overridden at
link and run time. */
&& targetm.binds_local_p (sym))
{ {
tree val = DECL_INITIAL (sym); tree val = DECL_INITIAL (sym);
if (val if (val
&& ccp_decl_initial_min_invariant (val)) && ccp_decl_initial_min_invariant (val))
return val; return val;
/* Variables declared 'const' without an initializer /* 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 if (!val
&& targetm.binds_local_p (sym)
&& (INTEGRAL_TYPE_P (TREE_TYPE (sym)) && (INTEGRAL_TYPE_P (TREE_TYPE (sym))
|| SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym)))) || SCALAR_FLOAT_TYPE_P (TREE_TYPE (sym))))
return fold_convert (TREE_TYPE (sym), integer_zero_node); return fold_convert (TREE_TYPE (sym), integer_zero_node);
...@@ -406,8 +405,12 @@ get_default_value (tree var) ...@@ -406,8 +405,12 @@ get_default_value (tree var)
static inline prop_value_t * static inline prop_value_t *
get_value (tree var) 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) if (val->lattice_val == UNINITIALIZED)
*val = get_default_value (var); *val = get_default_value (var);
...@@ -722,6 +725,7 @@ ccp_finalize (void) ...@@ -722,6 +725,7 @@ ccp_finalize (void)
bool something_changed = substitute_and_fold (const_val, false); bool something_changed = substitute_and_fold (const_val, false);
free (const_val); free (const_val);
const_val = NULL;
return something_changed;; return something_changed;;
} }
...@@ -1026,7 +1030,7 @@ ccp_fold (tree stmt) ...@@ -1026,7 +1030,7 @@ ccp_fold (tree stmt)
ARRAY_REF or COMPONENT_REF into constant aggregates. Return ARRAY_REF or COMPONENT_REF into constant aggregates. Return
NULL_TREE otherwise. */ NULL_TREE otherwise. */
static tree tree
fold_const_aggregate_ref (tree t) fold_const_aggregate_ref (tree t)
{ {
prop_value_t *value; prop_value_t *value;
......
...@@ -1597,48 +1597,46 @@ simplify_unary_expression (tree rhs) ...@@ -1597,48 +1597,46 @@ simplify_unary_expression (tree rhs)
static tree static tree
try_to_simplify (tree stmt, tree rhs) try_to_simplify (tree stmt, tree rhs)
{ {
tree tem;
/* For stores we can end up simplifying a SSA_NAME rhs. Just return /* For stores we can end up simplifying a SSA_NAME rhs. Just return
in this case, there is no point in doing extra work. */ in this case, there is no point in doing extra work. */
if (TREE_CODE (rhs) == SSA_NAME) if (TREE_CODE (rhs) == SSA_NAME)
return rhs; return rhs;
else
switch (TREE_CODE_CLASS (TREE_CODE (rhs)))
{ {
switch (TREE_CODE_CLASS (TREE_CODE (rhs))) case tcc_declaration:
{ tem = get_symbol_constant_value (rhs);
/* For references, see if we find a result for the lookup, if (tem)
and use it if we do. */ return tem;
case tcc_declaration: break;
/* Pull out any truly constant values. */
if (TREE_READONLY (rhs) case tcc_reference:
&& TREE_STATIC (rhs) /* Do not do full-blown reference lookup here, but simplify
&& DECL_INITIAL (rhs) reads from constant aggregates. */
&& valid_gimple_expression_p (DECL_INITIAL (rhs))) tem = fold_const_aggregate_ref (rhs);
return DECL_INITIAL (rhs); if (tem)
return tem;
/* Fallthrough. */
case tcc_reference: /* Fallthrough for some codes that can operate on registers. */
/* Do not do full-blown reference lookup here. if (!(TREE_CODE (rhs) == REALPART_EXPR
??? But like for tcc_declaration, we should simplify || TREE_CODE (rhs) == IMAGPART_EXPR
from constant initializers. */ || TREE_CODE (rhs) == VIEW_CONVERT_EXPR))
break;
/* Fallthrough for some codes that can operate on registers. */ /* We could do a little more with unary ops, if they expand
if (!(TREE_CODE (rhs) == REALPART_EXPR into binary ops, but it's debatable whether it is worth it. */
|| TREE_CODE (rhs) == IMAGPART_EXPR case tcc_unary:
|| TREE_CODE (rhs) == VIEW_CONVERT_EXPR)) return simplify_unary_expression (rhs);
break; break;
/* We could do a little more with unary ops, if they expand case tcc_comparison:
into binary ops, but it's debatable whether it is worth it. */ case tcc_binary:
case tcc_unary: return simplify_binary_expression (stmt, rhs);
return simplify_unary_expression (rhs); break;
break; default:
case tcc_comparison: break;
case tcc_binary:
return simplify_binary_expression (stmt, rhs);
break;
default:
break;
}
} }
return rhs; return rhs;
} }
......
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