From 8f119c559e7f56eb3deac726b32f70e2befaf58d Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Tue, 5 Nov 2019 09:50:39 +0000 Subject: [PATCH] Move vrp_set_zero_nonzero_bits from tree-vrp.c into vr-values.c, and make it use wi_set_zero_nonzero_bits. Move vrp_set_zero_nonzero_bits from tree-vrp.c into vr-values.c, and make it use wi_set_zero_nonzero_bits. Remove the now redundant wide_int_range_set_zero_nonzero_bits. From-SVN: r277818 --- gcc/ChangeLog | 11 +++++++++ gcc/range-op.cc | 2 +- gcc/range-op.h | 5 +++- gcc/tree-vrp.c | 63 ------------------------------------------------- gcc/tree-vrp.h | 2 -- gcc/vr-values.c | 32 +++++++++++++++++++++---- 6 files changed, 44 insertions(+), 71 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d11f3deac6..87b10805739 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-11-05 Aldy Hernandez + + * range-op.cc (wi_set_zero_nonzero_bits): Remove static qualifier. + * range-op.h (wi_set_zero_nonzero_bits): New prototype. + * tree-vrp.h (vrp_set_zero_nonzero_bits): Remove. + * tree-vrp.c (wide_int_range_set_zero_nonzero_bits): Remove. + (vrp_set_zero_nonzero_bits): Move to... + * vr-values.c (vr_set_zero_nonzero_bits): ...here. + (vr_values::simplify_bit_ops_using_ranges): Rename + vrp_set_zero_nonzero_bits to vr_set_zero_nonzero_bits. + 2019-11-05 Martin Liska PR c++/92339 diff --git a/gcc/range-op.cc b/gcc/range-op.cc index fc31485384b..56e8a20ad9e 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1847,7 +1847,7 @@ wi_optimize_and_or (value_range_base &r, // for all numbers in the range the bit is 1, otherwise it might be 0 // or 1. -static void +void wi_set_zero_nonzero_bits (tree type, const wide_int &lb, const wide_int &ub, wide_int &maybe_nonzero, diff --git a/gcc/range-op.h b/gcc/range-op.h index f6510758163..e531b918263 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -82,7 +82,10 @@ protected: }; extern range_operator *range_op_handler (enum tree_code code, tree type); - extern void range_cast (value_range_base &, tree type); +extern void wi_set_zero_nonzero_bits (tree type, + const wide_int &, const wide_int &, + wide_int &maybe_nonzero, + wide_int &mustbe_nonzero); #endif // GCC_RANGE_OP_H diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index e926670b962..e1d5c7cb98c 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1260,69 +1260,6 @@ value_range_base::value_inside_range (tree val) const return !!cmp2; } -/* For range [LB, UB] compute two wide_int bit masks. - - In the MAY_BE_NONZERO bit mask, if some bit is unset, it means that - for all numbers in the range the bit is 0, otherwise it might be 0 - or 1. - - In the MUST_BE_NONZERO bit mask, if some bit is set, it means that - for all numbers in the range the bit is 1, otherwise it might be 0 - or 1. */ - -static inline void -wide_int_range_set_zero_nonzero_bits (signop sign, - const wide_int &lb, const wide_int &ub, - wide_int &may_be_nonzero, - wide_int &must_be_nonzero) -{ - may_be_nonzero = wi::minus_one (lb.get_precision ()); - must_be_nonzero = wi::zero (lb.get_precision ()); - - if (wi::eq_p (lb, ub)) - { - may_be_nonzero = lb; - must_be_nonzero = may_be_nonzero; - } - else if (wi::ge_p (lb, 0, sign) || wi::lt_p (ub, 0, sign)) - { - wide_int xor_mask = lb ^ ub; - may_be_nonzero = lb | ub; - must_be_nonzero = lb & ub; - if (xor_mask != 0) - { - wide_int mask = wi::mask (wi::floor_log2 (xor_mask), false, - may_be_nonzero.get_precision ()); - may_be_nonzero = may_be_nonzero | mask; - must_be_nonzero = wi::bit_and_not (must_be_nonzero, mask); - } - } -} - -/* value_range wrapper for wide_int_range_set_zero_nonzero_bits above. - - Return TRUE if VR was a constant range and we were able to compute - the bit masks. */ - -bool -vrp_set_zero_nonzero_bits (const tree expr_type, - const value_range_base *vr, - wide_int *may_be_nonzero, - wide_int *must_be_nonzero) -{ - if (!range_int_cst_p (vr)) - { - *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type)); - *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type)); - return false; - } - wide_int_range_set_zero_nonzero_bits (TYPE_SIGN (expr_type), - wi::to_wide (vr->min ()), - wi::to_wide (vr->max ()), - *may_be_nonzero, *must_be_nonzero); - return true; -} - /* Create two value-ranges in *VR0 and *VR1 from the anti-range *AR so that *VR0 U *VR1 == *AR. Returns true if that is possible, false otherwise. If *AR can be represented with a single range diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index 3861634fb7e..0bf33caba85 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -299,8 +299,6 @@ void range_fold_binary_expr (value_range_base *, enum tree_code, tree type, extern bool vrp_operand_equal_p (const_tree, const_tree); extern enum value_range_kind intersect_range_with_nonzero_bits (enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop); -extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *, - wide_int *, wide_int *); extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *); extern bool find_case_label_index (gswitch *, size_t, tree, size_t *); diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 3acbfc60797..d1713bf4e0e 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -3341,6 +3341,30 @@ vr_values::simplify_abs_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt) return false; } +/* value_range wrapper for wi_set_zero_nonzero_bits. + + Return TRUE if VR was a constant range and we were able to compute + the bit masks. */ + +static bool +vr_set_zero_nonzero_bits (const tree expr_type, + const value_range_base *vr, + wide_int *may_be_nonzero, + wide_int *must_be_nonzero) +{ + if (range_int_cst_p (vr)) + { + wi_set_zero_nonzero_bits (expr_type, + wi::to_wide (vr->min ()), + wi::to_wide (vr->max ()), + *may_be_nonzero, *must_be_nonzero); + return true; + } + *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type)); + *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type)); + return false; +} + /* Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR. If all the bits that are being cleared by & are already known to be zero from VR, or all the bits that are being @@ -3373,11 +3397,11 @@ vr_values::simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, else return false; - if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0, - &must_be_nonzero0)) + if (!vr_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0, + &must_be_nonzero0)) return false; - if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1, - &must_be_nonzero1)) + if (!vr_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1, + &must_be_nonzero1)) return false; switch (gimple_assign_rhs_code (stmt)) -- 2.30.2