From a9058b08381cd76e8d21364f0f5ccddb3777c3fd Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Tue, 31 May 2022 14:04:51 +0200 Subject: Implement vrange::supports_type_p. [I have conservatively assumed that both the loop-ch and loop-unswitch passes, which also use the ranger, only support integers and pointers. If the goal is to handle other types as well, irange::supports_p() should be Value_Range::supports_type_p(), and any uses of int_range_max should be converted to Value_Range. I can help in the conversion if you'd like.] As discussed, this patch disambiguates the use of supports_type_p throughout, as what ranger supports is a totally different question than what a given range variant (irange, frange, etc) supports. Unfortunately we need both a static method and a virtual method, and they can't be named the same. The uses are documented in the vrange class: +// To query what types ranger and the entire ecosystem can support, +// use Value_Range::supports_type_p(tree type). This is a static +// method available independently of any vrange object. +// +// To query what a given vrange variant can support, use: +// irange::supports_p () +// frange::supports_p () +// etc +// +// To query what a range object can support, use: +// void foo (vrange &v, irange &i, frange &f) +// { +// if (v.supports_type_p (type)) ... +// if (i.supports_type_p (type)) ... +// if (f.supports_type_p (type)) ... +// } The value_range_equiv::supports_p() method can be use to determine what legacy VRP supports, as irange::supports_p() will no longer be applicable in the evrp analyzer code base once irange and prange are split. Tested on x86-64 Linux. gcc/ChangeLog: * gimple-range-edge.cc (gimple_outgoing_range_stmt_p): Adjust for an object level supports_type_p for irange and a static Value_Range::supports_type_p. * gimple-range-fold.cc (fold_using_range::range_of_range_op): Same. (fold_using_range::range_of_address): Same. (fold_using_range::range_of_builtin_call): Same. * gimple-range-fold.h (gimple_range_type): Same. (gimple_range_ssa_p): Same. * gimple-range-path.cc (path_range_query::internal_range_of_expr): Same. (path_range_query::range_of_stmt): Same. (path_range_query::add_to_imports): Same. * gimple-range.cc (gimple_ranger::range_on_edge): Same. (gimple_ranger::export_global_ranges): Same. * gimple-ssa-evrp-analyze.cc (evrp_range_analyzer::record_ranges_from_phis): Same. * range-op.cc (range_operator::wi_fold): Same. (range_operator::fold_range): Same. * tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Same. * tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Same. (evaluate_control_stmt_using_entry_checks): Same. * tree-ssa-threadedge.cc (hybrid_jt_simplifier::compute_ranges_from_state): Same. * tree-vrp.cc (supported_types_p): Same. * value-query.cc (range_query::value_of_expr): Same. (range_query::value_on_edge): Same. (range_query::value_of_stmt): Same. (range_query::get_tree_range): Same. (get_range_global): Same. (global_range_query::range_of_expr): Same. * value-range-equiv.h (class value_range_equiv): Same. * value-range.cc (irange::supports_type_p): Same. (unsupported_range::supports_type_p): Same. * value-range.h (enum value_range_discriminator): Same. (Value_Range::init): Same. (Value_Range::supports_type_p): Same. (irange::supports_type_p): Same. (irange::supports_p): Same. (vrange::supports_type_p): Same. (vrange_allocator::alloc_vrange): Same. --- gcc/value-query.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'gcc/value-query.cc') diff --git a/gcc/value-query.cc b/gcc/value-query.cc index e40e358..1d7541c 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -80,7 +80,7 @@ range_query::value_of_expr (tree expr, gimple *stmt) { tree t; - if (!vrange::supports_type_p (TREE_TYPE (expr))) + if (!Value_Range::supports_type_p (TREE_TYPE (expr))) return NULL_TREE; Value_Range r (TREE_TYPE (expr)); @@ -102,7 +102,7 @@ range_query::value_on_edge (edge e, tree expr) { tree t; - if (!vrange::supports_type_p (TREE_TYPE (expr))) + if (!Value_Range::supports_type_p (TREE_TYPE (expr))) return NULL_TREE; Value_Range r (TREE_TYPE (expr)); if (range_on_edge (r, e, expr)) @@ -128,7 +128,7 @@ range_query::value_of_stmt (gimple *stmt, tree name) gcc_checking_assert (!name || name == gimple_get_lhs (stmt)); - if (!name || !vrange::supports_type_p (TREE_TYPE (name))) + if (!name || !Value_Range::supports_type_p (TREE_TYPE (name))) return NULL_TREE; Value_Range r (TREE_TYPE (name)); if (range_of_stmt (r, stmt, name) && r.singleton_p (&t)) @@ -196,7 +196,7 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) else type = TREE_TYPE (expr); - if (!vrange::supports_type_p (type)) + if (!Value_Range::supports_type_p (type)) { r.set_undefined (); return false; @@ -252,7 +252,7 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) { range_op_handler op (TREE_CODE (expr), type); tree op0_type = TREE_TYPE (TREE_OPERAND (expr, 0)); - if (op && vrange::supports_type_p (op0_type)) + if (op && Value_Range::supports_type_p (op0_type)) { Value_Range r0 (TREE_TYPE (TREE_OPERAND (expr, 0))); Value_Range r1 (type); @@ -387,7 +387,7 @@ get_range_global (vrange &r, tree name) } else if (!POINTER_TYPE_P (type) && SSA_NAME_RANGE_INFO (name)) { - gcc_checking_assert (irange::supports_type_p (TREE_TYPE (name))); + gcc_checking_assert (irange::supports_p (TREE_TYPE (name))); get_ssa_name_range_info (as_a (r), name); if (r.undefined_p ()) r.set_varying (type); @@ -441,9 +441,7 @@ global_range_query global_ranges; bool global_range_query::range_of_expr (vrange &r, tree expr, gimple *stmt) { - tree type = TREE_TYPE (expr); - - if (!irange::supports_type_p (type) || !gimple_range_ssa_p (expr)) + if (!gimple_range_ssa_p (expr)) return get_tree_range (r, expr, stmt); get_range_global (r, expr); -- cgit v1.1