aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2011-03-24 11:23:29 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2011-03-24 11:23:29 +0000
commitcfef45c8097d122e7dfda42c5e2767bf21a7f649 (patch)
treedf3f9f4a9233142004cc074157b5b3c2abf3bcb5 /gcc/tree-vrp.c
parentf3e8ab1973c02daace2d7be9dbf03be03a7b3669 (diff)
downloadgcc-cfef45c8097d122e7dfda42c5e2767bf21a7f649.zip
gcc-cfef45c8097d122e7dfda42c5e2767bf21a7f649.tar.gz
gcc-cfef45c8097d122e7dfda42c5e2767bf21a7f649.tar.bz2
re PR tree-optimization/46562 (CCP currently needs iteration for &a[i])
2011-03-24 Richard Guenther <rguenther@suse.de> PR tree-optimization/46562 * tree.c (build_invariant_address): New function. * tree.h (build_invariant_address): Declare. * tree-dfa.c (get_addr_base_and_unit_offset): Wrap around a renamed function moved ... * tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here. Take valueization callback parameter. * tree-flow.h (gimple_fold_stmt_to_constant): Declare. * gimple-fold.h: New file. * tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1. (ccp_fold, fold_const_aggregate_ref, fold_ctor_reference, fold_nonarray_ctor_reference, fold_array_ctor_reference, fold_string_cst_ctor_reference, get_base_constructor): Move ... * gimple-fold.c: ... here. (gimple_fold_stmt_to_constant_1): New function split out from ccp_fold. Take a valueization callback parameter. Valueize all operands. (gimple_fold_stmt_to_constant): New wrapper function. (fold_const_aggregate_ref_1): New function split out from fold_const_aggregate_ref. Take a valueization callback parameter. (fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1. * tree-ssa-sccvn.c (simplify_binary_expression): Simplify invariant POINTER_PLUS_EXPRs to invariant form. (vn_valueize): New function. (try_to_simplify): Simplify by using gimple_fold_stmt_to_constant. * tree-vrp.c (vrp_valueize): New function. (vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant to fold statements to constants. * tree-ssa-pre.c (eliminate): Properly guard propagation of function declarations. * Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o, tree-ssa-ccp.o): Add gimple-fold.h dependencies. * c-c++-common/pr46562-2.c: New testcase. * c-c++-common/pr46562.c: Likewise. From-SVN: r171386
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 42ea910..466c3a0 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-scalar-evolution.h"
#include "tree-ssa-propagate.h"
#include "tree-chrec.h"
+#include "gimple-fold.h"
/* Type of value ranges. See value_range_d for a description of these
@@ -5614,6 +5615,21 @@ vrp_initialize (void)
}
}
+/* Return the singleton value-range for NAME or NAME. */
+
+static inline tree
+vrp_valueize (tree name)
+{
+ if (TREE_CODE (name) == SSA_NAME)
+ {
+ value_range_t *vr = get_value_range (name);
+ if (vr->type == VR_RANGE
+ && (vr->min == vr->max
+ || operand_equal_p (vr->min, vr->max, 0)))
+ return vr->min;
+ }
+ return name;
+}
/* Visit assignment STMT. If it produces an interesting range, record
the SSA name in *OUTPUT_P. */
@@ -5637,7 +5653,12 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
{
value_range_t new_vr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL };
- if (code == GIMPLE_CALL)
+ /* Try folding the statement to a constant first. */
+ tree tem = gimple_fold_stmt_to_constant (stmt, vrp_valueize);
+ if (tem && !is_overflow_infinity (tem))
+ set_value_range (&new_vr, VR_RANGE, tem, tem, NULL);
+ /* Then dispatch to value-range extracting functions. */
+ else if (code == GIMPLE_CALL)
extract_range_basic (&new_vr, stmt);
else
extract_range_from_assignment (&new_vr, stmt);
@@ -6366,7 +6387,6 @@ vrp_visit_stmt (gimple stmt, edge *taken_edge_p, tree *output_p)
/* In general, assignments with virtual operands are not useful
for deriving ranges, with the obvious exception of calls to
builtin functions. */
-
if ((is_gimple_call (stmt)
&& gimple_call_fndecl (stmt) != NULL_TREE
&& DECL_IS_BUILTIN (gimple_call_fndecl (stmt)))