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>
* 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
* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Make sure
to not produce negative array indices if not allowed. Add
......
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
* g++.dg/warn/Warray-bounds-3.C: New testcase.
/* 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" } } */
......@@ -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)
......
......@@ -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; }
......@@ -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 */
......
......@@ -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;
......
......@@ -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;
}
......
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