aboutsummaryrefslogtreecommitdiff
path: root/gcc/value-range.h
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2023-03-02 16:34:46 +0100
committerAldy Hernandez <aldyh@redhat.com>2023-05-01 08:33:12 +0200
commitcb779afeff204fdb278e55006ea7d269a4606d85 (patch)
tree15ca32f9f066f6d052a21e88fae64755659930b7 /gcc/value-range.h
parent612d373005ad239001fd61f32950cb146e1084bc (diff)
downloadgcc-cb779afeff204fdb278e55006ea7d269a4606d85.zip
gcc-cb779afeff204fdb278e55006ea7d269a4606d85.tar.gz
gcc-cb779afeff204fdb278e55006ea7d269a4606d85.tar.bz2
Conversion to irange wide_int API.
This converts the irange API to use wide_ints exclusively, along with its users. This patch will slow down VRP, as there will be more useless wide_int to tree conversions. However, this slowdown is only temporary, as a follow-up patch will convert the internal representation of iranges to wide_ints for a net overall gain in performance. gcc/ChangeLog: * fold-const.cc (expr_not_equal_to): Convert to irange wide_int API. * gimple-fold.cc (size_must_be_zero_p): Same. * gimple-loop-versioning.cc (loop_versioning::prune_loop_conditions): Same. * gimple-range-edge.cc (gcond_edge_range): Same. (gimple_outgoing_range::calc_switch_ranges): Same. * gimple-range-fold.cc (adjust_imagpart_expr): Same. (adjust_realpart_expr): Same. (fold_using_range::range_of_address): Same. (fold_using_range::relation_fold_and_or): Same. * gimple-range-gori.cc (gori_compute::gori_compute): Same. (range_is_either_true_or_false): Same. * gimple-range-op.cc (cfn_toupper_tolower::get_letter_range): Same. (cfn_clz::fold_range): Same. (cfn_ctz::fold_range): Same. * gimple-range-tests.cc (class test_expr_eval): Same. * gimple-ssa-warn-alloca.cc (alloca_call_type): Same. * ipa-cp.cc (ipa_value_range_from_jfunc): Same. (propagate_vr_across_jump_function): Same. (decide_whether_version_node): Same. * ipa-prop.cc (ipa_get_value_range): Same. * ipa-prop.h (ipa_range_set_and_normalize): Same. * range-op.cc (get_shift_range): Same. (value_range_from_overflowed_bounds): Same. (value_range_with_overflow): Same. (create_possibly_reversed_range): Same. (equal_op1_op2_relation): Same. (not_equal_op1_op2_relation): Same. (lt_op1_op2_relation): Same. (le_op1_op2_relation): Same. (gt_op1_op2_relation): Same. (ge_op1_op2_relation): Same. (operator_mult::op1_range): Same. (operator_exact_divide::op1_range): Same. (operator_lshift::op1_range): Same. (operator_rshift::op1_range): Same. (operator_cast::op1_range): Same. (operator_logical_and::fold_range): Same. (set_nonzero_range_from_mask): Same. (operator_bitwise_or::op1_range): Same. (operator_bitwise_xor::op1_range): Same. (operator_addr_expr::fold_range): Same. (pointer_plus_operator::wi_fold): Same. (pointer_or_operator::op1_range): Same. (INT): Same. (UINT): Same. (INT16): Same. (UINT16): Same. (SCHAR): Same. (UCHAR): Same. (range_op_cast_tests): Same. (range_op_lshift_tests): Same. (range_op_rshift_tests): Same. (range_op_bitwise_and_tests): Same. (range_relational_tests): Same. * range.cc (range_zero): Same. (range_nonzero): Same. * range.h (range_true): Same. (range_false): Same. (range_true_and_false): Same. * tree-data-ref.cc (split_constant_offset_1): Same. * tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Same. * tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Same. (find_unswitching_predicates_for_bb): Same. * tree-ssa-phiopt.cc (value_replacement): Same. * tree-ssa-threadbackward.cc (back_threader::find_taken_edge_cond): Same. * tree-ssanames.cc (ssa_name_has_boolean_range): Same. * tree-vrp.cc (find_case_label_range): Same. * value-query.cc (range_query::get_tree_range): Same. * value-range.cc (irange::set_nonnegative): Same. (frange::contains_p): Same. (frange::singleton_p): Same. (frange::internal_singleton_p): Same. (irange::irange_set): Same. (irange::irange_set_1bit_anti_range): Same. (irange::irange_set_anti_range): Same. (irange::set): Same. (irange::operator==): Same. (irange::singleton_p): Same. (irange::contains_p): Same. (irange::set_range_from_nonzero_bits): Same. (DEFINE_INT_RANGE_INSTANCE): Same. (INT): Same. (UINT): Same. (SCHAR): Same. (UINT128): Same. (UCHAR): Same. (range): New. (tree_range): New. (range_int): New. (range_uint): New. (range_uint128): New. (range_uchar): New. (range_char): New. (build_range3): Convert to irange wide_int API. (range_tests_irange3): Same. (range_tests_int_range_max): Same. (range_tests_strict_enum): Same. (range_tests_misc): Same. (range_tests_nonzero_bits): Same. (range_tests_nan): Same. (range_tests_signed_zeros): Same. * value-range.h (Value_Range::Value_Range): Same. (irange::set): Same. (irange::nonzero_p): Same. (irange::contains_p): Same. (range_includes_zero_p): Same. (irange::set_nonzero): Same. (irange::set_zero): Same. (contains_zero_p): Same. (frange::contains_p): Same. * vr-values.cc (simplify_using_ranges::op_with_boolean_value_range_p): Same. (bounds_of_var_in_loop): Same. (simplify_using_ranges::legacy_fold_cond_overflow): Same.
Diffstat (limited to 'gcc/value-range.h')
-rw-r--r--gcc/value-range.h75
1 files changed, 49 insertions, 26 deletions
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 6d10815..633a234 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -122,8 +122,7 @@ class GTY((user)) irange : public vrange
friend class irange_storage;
public:
// In-place setters.
- virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
- void set (tree type, const wide_int_ref &, const wide_int_ref &,
+ void set (tree type, const wide_int &, const wide_int &,
value_range_kind = VR_RANGE);
virtual void set_nonzero (tree type) override;
virtual void set_zero (tree type) override;
@@ -146,7 +145,8 @@ public:
virtual bool zero_p () const override;
virtual bool nonzero_p () const override;
virtual bool singleton_p (tree *result = NULL) const override;
- virtual bool contains_p (tree cst) const override;
+ bool singleton_p (wide_int &) const;
+ bool contains_p (const wide_int &) const;
// In-place operators.
virtual bool union_ (const vrange &) override;
@@ -167,11 +167,13 @@ public:
void set_nonzero_bits (const wide_int_ref &bits);
protected:
+ virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
+ virtual bool contains_p (tree cst) const override;
irange (tree *, unsigned);
// In-place operators.
- void irange_set (tree, tree);
- void irange_set_anti_range (tree, tree);
+ void irange_set (tree type, const wide_int &, const wide_int &);
+ void irange_set_anti_range (tree type, const wide_int &, const wide_int &);
bool irange_contains_p (const irange &) const;
bool irange_single_pair_union (const irange &r);
@@ -184,7 +186,8 @@ private:
friend void gt_pch_nx (irange *);
friend void gt_pch_nx (irange *, gt_pointer_operator, void *);
- void irange_set_1bit_anti_range (tree, tree);
+ void irange_set_1bit_anti_range (tree type,
+ const wide_int &, const wide_int &);
bool varying_compatible_p () const;
bool intersect_nonzero_bits (const irange &r);
bool union_nonzero_bits (const irange &r);
@@ -206,7 +209,6 @@ class GTY((user)) int_range : public irange
{
public:
int_range ();
- int_range (tree, tree, value_range_kind = VR_RANGE);
int_range (tree type, const wide_int &, const wide_int &,
value_range_kind = VR_RANGE);
int_range (tree type);
@@ -214,6 +216,8 @@ public:
int_range (const irange &);
virtual ~int_range () = default;
int_range& operator= (const int_range &);
+protected:
+ int_range (tree, tree, value_range_kind = VR_RANGE);
private:
template <unsigned X> friend void gt_ggc_mx (int_range<X> *);
template <unsigned X> friend void gt_pch_nx (int_range<X> *);
@@ -319,7 +323,6 @@ public:
return SCALAR_FLOAT_TYPE_P (type) && !DECIMAL_FLOAT_TYPE_P (type);
}
virtual tree type () const override;
- virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
void set (tree type, const REAL_VALUE_TYPE &, const REAL_VALUE_TYPE &,
value_range_kind = VR_RANGE);
void set (tree type, const REAL_VALUE_TYPE &, const REAL_VALUE_TYPE &,
@@ -330,8 +333,9 @@ public:
virtual void set_undefined () override;
virtual bool union_ (const vrange &) override;
virtual bool intersect (const vrange &) override;
- virtual bool contains_p (tree) const override;
+ bool contains_p (const REAL_VALUE_TYPE &) const;
virtual bool singleton_p (tree *result = NULL) const override;
+ bool singleton_p (REAL_VALUE_TYPE &r) const;
virtual bool supports_type_p (const_tree type) const override;
virtual void accept (const vrange_visitor &v) const override;
virtual bool zero_p () const override;
@@ -361,7 +365,13 @@ public:
bool maybe_isinf () const;
bool signbit_p (bool &signbit) const;
bool nan_signbit_p (bool &signbit) const;
+
+protected:
+ virtual bool contains_p (tree cst) const override;
+ virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
+
private:
+ bool internal_singleton_p (REAL_VALUE_TYPE * = NULL) const;
void verify_range ();
bool normalize_kind ();
bool union_nans (const frange &);
@@ -485,8 +495,6 @@ public:
static bool supports_type_p (const_tree type);
// Convenience methods for vrange compatibility.
- void set (tree min, tree max, value_range_kind kind = VR_RANGE)
- { return m_vrange->set (min, max, kind); }
tree type () { return m_vrange->type (); }
bool varying_p () const { return m_vrange->varying_p (); }
bool undefined_p () const { return m_vrange->undefined_p (); }
@@ -536,7 +544,7 @@ inline
Value_Range::Value_Range (tree min, tree max, value_range_kind kind)
{
init (TREE_TYPE (min));
- set (min, max, kind);
+ m_vrange->set (min, max, kind);
}
inline
@@ -674,13 +682,6 @@ irange::varying_compatible_p () const
return true;
}
-inline void
-irange::set (tree type, const wide_int_ref &min, const wide_int_ref &max,
- value_range_kind kind)
-{
- set (wide_int_to_tree (type, min), wide_int_to_tree (type, max), kind);
-}
-
inline bool
vrange::varying_p () const
{
@@ -707,8 +708,8 @@ irange::nonzero_p () const
if (undefined_p ())
return false;
- tree zero = build_zero_cst (type ());
- return *this == int_range<2> (zero, zero, VR_ANTI_RANGE);
+ wide_int zero = wi::zero (TYPE_PRECISION (type ()));
+ return *this == int_range<2> (type (), zero, zero, VR_ANTI_RANGE);
}
inline bool
@@ -718,6 +719,12 @@ irange::supports_p (const_tree type)
}
inline bool
+irange::contains_p (tree cst) const
+{
+ return contains_p (wi::to_wide (cst));
+}
+
+inline bool
range_includes_zero_p (const irange *vr)
{
if (vr->undefined_p ())
@@ -726,7 +733,7 @@ range_includes_zero_p (const irange *vr)
if (vr->varying_p ())
return true;
- tree zero = build_zero_cst (vr->type ());
+ wide_int zero = wi::zero (TYPE_PRECISION (vr->type ()));
return vr->contains_p (zero);
}
@@ -906,8 +913,8 @@ irange::upper_bound () const
inline void
irange::set_nonzero (tree type)
{
- tree zero = build_int_cst (type, 0);
- irange_set_anti_range (zero, zero);
+ wide_int zero = wi::zero (TYPE_PRECISION (type));
+ set (type, zero, zero, VR_ANTI_RANGE);
}
// Set value range VR to a ZERO range of type TYPE.
@@ -915,8 +922,8 @@ irange::set_nonzero (tree type)
inline void
irange::set_zero (tree type)
{
- tree z = build_int_cst (type, 0);
- irange_set (z, z);
+ wide_int zero = wi::zero (TYPE_PRECISION (type));
+ set (type, zero, zero);
}
// Normalize a range to VARYING or UNDEFINED if possible.
@@ -935,6 +942,16 @@ irange::normalize_kind ()
}
}
+inline bool
+contains_zero_p (const irange &r)
+{
+ if (r.undefined_p ())
+ return true;
+
+ wide_int zero = wi::zero (TYPE_PRECISION (r.type ()));
+ return r.contains_p (zero);
+}
+
// Return the maximum value for TYPE.
inline tree
@@ -1083,6 +1100,12 @@ frange::update_nan (bool sign)
}
}
+inline bool
+frange::contains_p (tree cst) const
+{
+ return contains_p (*TREE_REAL_CST_PTR (cst));
+}
+
// Clear the NAN bit and adjust the range.
inline void