+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>
* fold-const.c (fold_negate_expr): Don't fold INTEGER_CST if
to avoid the indirect function call overhead. */
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;
tree ops[3] = {};
edges if there are intermediate VARYING defs. For this reason
do not follow SSA edges here even though SCCVN can technically
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 ()
&& (TREE_CODE_LENGTH ((tree_code) rcode) == 0
|| ((tree_code) rcode) == ADDR_EXPR)
const_tree);
extern tree no_follow_ssa_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 fold_const_aggregate_ref_1 (tree, tree (*) (tree));
extern tree fold_const_aggregate_ref (tree);
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
routines.
case GIMPLE_ASSIGN:
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:
gcc_unreachable ();
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
the SSA name in *OUTPUT_P. */
value_range_t new_vr = VR_INITIALIZER;
/* Try folding the statement to a constant first. */
- tree tem = gimple_fold_stmt_to_constant (stmt, vrp_valueize);
- if (tem)
+ tree tem = gimple_fold_stmt_to_constant_1 (stmt, vrp_valueize,
+ vrp_valueize_1);
+ if (tem && is_gimple_min_invariant (tem))
set_value_range_to_value (&new_vr, tem, NULL);
/* Then dispatch to value-range extracting functions. */
else if (code == GIMPLE_CALL)