Commit d2a85801 by Richard Biener Committed by Richard Biener

gimple-fold.h (gimple_fold_stmt_to_constant_1): Add 2nd valueization hook…

gimple-fold.h (gimple_fold_stmt_to_constant_1): Add 2nd valueization hook defaulted to no_follow_ssa_edges.

2014-11-14  Richard Biener  <rguenther@suse.de>

	* gimple-fold.h (gimple_fold_stmt_to_constant_1): Add 2nd
	valueization hook defaulted to no_follow_ssa_edges.
	* gimple-fold.c (gimple_fold_stmt_to_constant_1): Pass
	2nd valueization hook to gimple_simplify.
	* tree-ssa-ccp.c (valueize_op_1): New function to be
	used for gimple_simplify called via gimple_fold_stmt_to_constant_1.
	(ccp_fold): Adjust.
	* tree-vrp.c (vrp_valueize_1): New function to be
	used for gimple_simplify called via gimple_fold_stmt_to_constant_1.
	(vrp_visit_assignment_or_call): Adjust.

From-SVN: r217560
parent a5dde6dd
2014-11-14 Richard Biener <rguenther@suse.de>
* gimple-fold.h (gimple_fold_stmt_to_constant_1): Add 2nd
valueization hook defaulted to no_follow_ssa_edges.
* gimple-fold.c (gimple_fold_stmt_to_constant_1): Pass
2nd valueization hook to gimple_simplify.
* tree-ssa-ccp.c (valueize_op_1): New function to be
used for gimple_simplify called via gimple_fold_stmt_to_constant_1.
(ccp_fold): Adjust.
* tree-vrp.c (vrp_valueize_1): New function to be
used for gimple_simplify called via gimple_fold_stmt_to_constant_1.
(vrp_visit_assignment_or_call): Adjust.
2014-11-14 Marek Polacek <polacek@redhat.com> 2014-11-14 Marek Polacek <polacek@redhat.com>
* fold-const.c (fold_negate_expr): Don't fold INTEGER_CST if * fold-const.c (fold_negate_expr): Don't fold INTEGER_CST if
...@@ -4467,7 +4467,8 @@ maybe_fold_or_comparisons (enum tree_code code1, tree op1a, tree op1b, ...@@ -4467,7 +4467,8 @@ maybe_fold_or_comparisons (enum tree_code code1, tree op1a, tree op1b,
to avoid the indirect function call overhead. */ to avoid the indirect function call overhead. */
tree tree
gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree)) gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree),
tree (*gvalueize) (tree))
{ {
code_helper rcode; code_helper rcode;
tree ops[3] = {}; tree ops[3] = {};
...@@ -4475,7 +4476,7 @@ gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree)) ...@@ -4475,7 +4476,7 @@ gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree))
edges if there are intermediate VARYING defs. For this reason edges if there are intermediate VARYING defs. For this reason
do not follow SSA edges here even though SCCVN can technically do not follow SSA edges here even though SCCVN can technically
just deal fine with that. */ just deal fine with that. */
if (gimple_simplify (stmt, &rcode, ops, NULL, no_follow_ssa_edges) if (gimple_simplify (stmt, &rcode, ops, NULL, gvalueize)
&& rcode.is_tree_code () && rcode.is_tree_code ()
&& (TREE_CODE_LENGTH ((tree_code) rcode) == 0 && (TREE_CODE_LENGTH ((tree_code) rcode) == 0
|| ((tree_code) rcode) == ADDR_EXPR) || ((tree_code) rcode) == ADDR_EXPR)
......
...@@ -36,7 +36,8 @@ extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree, ...@@ -36,7 +36,8 @@ extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree,
const_tree); const_tree);
extern tree no_follow_ssa_edges (tree); extern tree no_follow_ssa_edges (tree);
extern tree follow_single_use_edges (tree); extern tree follow_single_use_edges (tree);
extern tree gimple_fold_stmt_to_constant_1 (gimple, tree (*) (tree)); extern tree gimple_fold_stmt_to_constant_1 (gimple, tree (*) (tree),
tree (*) (tree) = no_follow_ssa_edges);
extern tree gimple_fold_stmt_to_constant (gimple, tree (*) (tree)); extern tree gimple_fold_stmt_to_constant (gimple, tree (*) (tree));
extern tree fold_const_aggregate_ref_1 (tree, tree (*) (tree)); extern tree fold_const_aggregate_ref_1 (tree, tree (*) (tree));
extern tree fold_const_aggregate_ref (tree); extern tree fold_const_aggregate_ref (tree);
......
...@@ -1126,6 +1126,27 @@ valueize_op (tree op) ...@@ -1126,6 +1126,27 @@ valueize_op (tree op)
return op; return op;
} }
/* Return the constant value for OP, but signal to not follow SSA
edges if the definition may be simulated again. */
static tree
valueize_op_1 (tree op)
{
if (TREE_CODE (op) == SSA_NAME)
{
tree tem = get_constant_value (op);
if (tem)
return tem;
/* If the definition may be simulated again we cannot follow
this SSA edge as the SSA propagator does not necessarily
re-visit the use. */
gimple def_stmt = SSA_NAME_DEF_STMT (op);
if (prop_simulate_again_p (def_stmt))
return NULL_TREE;
}
return op;
}
/* CCP specific front-end to the non-destructive constant folding /* CCP specific front-end to the non-destructive constant folding
routines. routines.
...@@ -1158,7 +1179,8 @@ ccp_fold (gimple stmt) ...@@ -1158,7 +1179,8 @@ ccp_fold (gimple stmt)
case GIMPLE_ASSIGN: case GIMPLE_ASSIGN:
case GIMPLE_CALL: case GIMPLE_CALL:
return gimple_fold_stmt_to_constant_1 (stmt, valueize_op); return gimple_fold_stmt_to_constant_1 (stmt,
valueize_op, valueize_op_1);
default: default:
gcc_unreachable (); gcc_unreachable ();
......
...@@ -7025,6 +7025,27 @@ vrp_valueize (tree name) ...@@ -7025,6 +7025,27 @@ vrp_valueize (tree name)
return name; return name;
} }
/* Return the singleton value-range for NAME if that is a constant
but signal to not follow SSA edges. */
static inline tree
vrp_valueize_1 (tree name)
{
if (TREE_CODE (name) == SSA_NAME)
{
value_range_t *vr = get_value_range (name);
if (range_int_cst_singleton_p (vr))
return vr->min;
/* If the definition may be simulated again we cannot follow
this SSA edge as the SSA propagator does not necessarily
re-visit the use. */
gimple def_stmt = SSA_NAME_DEF_STMT (name);
if (prop_simulate_again_p (def_stmt))
return NULL_TREE;
}
return name;
}
/* Visit assignment STMT. If it produces an interesting range, record /* Visit assignment STMT. If it produces an interesting range, record
the SSA name in *OUTPUT_P. */ the SSA name in *OUTPUT_P. */
...@@ -7048,8 +7069,9 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p) ...@@ -7048,8 +7069,9 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p)
value_range_t new_vr = VR_INITIALIZER; value_range_t new_vr = VR_INITIALIZER;
/* Try folding the statement to a constant first. */ /* Try folding the statement to a constant first. */
tree tem = gimple_fold_stmt_to_constant (stmt, vrp_valueize); tree tem = gimple_fold_stmt_to_constant_1 (stmt, vrp_valueize,
if (tem) vrp_valueize_1);
if (tem && is_gimple_min_invariant (tem))
set_value_range_to_value (&new_vr, tem, NULL); set_value_range_to_value (&new_vr, tem, NULL);
/* Then dispatch to value-range extracting functions. */ /* Then dispatch to value-range extracting functions. */
else if (code == GIMPLE_CALL) else if (code == GIMPLE_CALL)
......
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