From e1d01f4973eee8d229ddc326ff7c3bd5f4cf32c1 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Sat, 25 Sep 2021 13:02:21 +0200 Subject: [PATCH] Convert some evrp uses in DOM to the range_query API. DOM is the last remaining user of the evrp engine. This patch converts a few uses of the engine and vr-values into the new API. There is one subtle change. The call to vr_value's op_with_constant_singleton_value_range can theoretically return non-constants, unlike the range_query API which only returns constants. In this particular case it doesn't matter because the symbolic stuff will have been handled by the const_and_copies/avail_exprs read in the SSA_NAME_VALUE copy immediately before. I have verified this is the case by asserting that all calls to op_with_constant_singleton_value_range at this point return either NULL or an INTEGER_CST. Tested on x86-64 Linux with a regstrap, as well as the aforementioned assert. gcc/ChangeLog: * gimple-ssa-evrp-analyze.h (class evrp_range_analyzer): Remove vrp_visit_cond_stmt. * tree-ssa-dom.c (cprop_operand): Convert to range_query API. (cprop_into_stmt): Same. (dom_opt_dom_walker::optimize_stmt): Same. --- gcc/gimple-ssa-evrp-analyze.h | 7 ------- gcc/tree-ssa-dom.c | 17 +++++++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/gcc/gimple-ssa-evrp-analyze.h b/gcc/gimple-ssa-evrp-analyze.h index 0a70a1e..4cf82e6 100644 --- a/gcc/gimple-ssa-evrp-analyze.h +++ b/gcc/gimple-ssa-evrp-analyze.h @@ -38,13 +38,6 @@ class evrp_range_analyzer : public vr_values /* Record a new unwindable range. */ void push_value_range (tree var, value_range_equiv *vr); - /* A bit of a wart. This should ideally go away. */ - void vrp_visit_cond_stmt (gcond *cond, edge *e) - { - simplify_using_ranges simpl (this); - simpl.vrp_visit_cond_stmt (cond, e); - } - private: DISABLE_COPY_AND_ASSIGN (evrp_range_analyzer); diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index f58b6b7..a8a5b34 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1810,7 +1810,7 @@ record_equivalences_from_stmt (gimple *stmt, int may_optimize_p, CONST_AND_COPIES. */ static void -cprop_operand (gimple *stmt, use_operand_p op_p, vr_values *vr_values) +cprop_operand (gimple *stmt, use_operand_p op_p, range_query *query) { tree val; tree op = USE_FROM_PTR (op_p); @@ -1820,7 +1820,12 @@ cprop_operand (gimple *stmt, use_operand_p op_p, vr_values *vr_values) CONST_AND_COPIES. */ val = SSA_NAME_VALUE (op); if (!val) - val = vr_values->op_with_constant_singleton_value_range (op); + { + value_range r; + tree single; + if (query->range_of_expr (r, op, stmt) && r.singleton_p (&single)) + val = single; + } if (val && val != op) { @@ -1878,7 +1883,7 @@ cprop_operand (gimple *stmt, use_operand_p op_p, vr_values *vr_values) vdef_ops of STMT. */ static void -cprop_into_stmt (gimple *stmt, vr_values *vr_values) +cprop_into_stmt (gimple *stmt, range_query *query) { use_operand_p op_p; ssa_op_iter iter; @@ -1895,7 +1900,7 @@ cprop_into_stmt (gimple *stmt, vr_values *vr_values) operands. */ if (old_op != last_copy_propagated_op) { - cprop_operand (stmt, op_p, vr_values); + cprop_operand (stmt, op_p, query); tree new_op = USE_FROM_PTR (op_p); if (new_op != old_op && TREE_CODE (new_op) == SSA_NAME) @@ -2203,8 +2208,8 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si, SSA_NAMES. */ update_stmt_if_modified (stmt); edge taken_edge = NULL; - m_evrp_range_analyzer->vrp_visit_cond_stmt - (as_a (stmt), &taken_edge); + simplify_using_ranges simpl (m_evrp_range_analyzer); + simpl.vrp_visit_cond_stmt (as_a (stmt), &taken_edge); if (taken_edge) { if (taken_edge->flags & EDGE_TRUE_VALUE) -- 2.7.4