From: aldyh Date: Tue, 4 Sep 2018 11:58:14 +0000 (+0000) Subject: * tree-vrp.c (vrp_can_optimize_bit_op): Remove. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0c8c617bd3c055f6e155075ecf37eebc2889814;p=thirdparty%2Fgcc.git * tree-vrp.c (vrp_can_optimize_bit_op): Remove. (extract_range_from_binary_expr_1): Do not call vrp_can_optimize_bit_op. * wide-int-range.cc (wide_int_range_can_optimize_bit_op): Make static. (wide_int_range_get_mask_and_bounds): New. (wide_int_range_optimize_bit_op): New. (wide_int_range_bit_ior): Call wide_int_range_optimize_bit_op. (wide_int_range_bit_and): Same. * wide-int-range.h (wide_int_range_can_optimize_bit_op): Remove. (wide_int_range_optimize_bit_op): New. (wide_int_range_get_mask_and_bounds): New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264078 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cfd6b2500c83..afa7e5bf69e5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2018-09-04 Aldy Hernandez + + * tree-vrp.c (vrp_can_optimize_bit_op): Remove. + (extract_range_from_binary_expr_1): Do not call + vrp_can_optimize_bit_op. + * wide-int-range.cc (wide_int_range_can_optimize_bit_op): Make + static. + (wide_int_range_get_mask_and_bounds): New. + (wide_int_range_optimize_bit_op): New. + (wide_int_range_bit_ior): Call wide_int_range_optimize_bit_op. + (wide_int_range_bit_and): Same. + * wide-int-range.h (wide_int_range_can_optimize_bit_op): Remove. + (wide_int_range_optimize_bit_op): New. + (wide_int_range_get_mask_and_bounds): New. + 2018-09-04 Richard Biener PR tree-optimization/87176 diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index c1774dc736cc..d29a2c9b5077 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1067,49 +1067,6 @@ extract_range_from_multiplicative_op (value_range *vr, set_value_range_to_varying (vr); } -/* Value range wrapper for wide_int_range_can_optimize_bit_op. - - If a bit operation on two ranges can be easily optimized in terms - of a mask, store the optimized new range in VR and return TRUE. */ - -static bool -vrp_can_optimize_bit_op (value_range *vr, enum tree_code code, - const value_range *vr0, const value_range *vr1) -{ - tree lower_bound, upper_bound, mask; - if (code != BIT_AND_EXPR && code != BIT_IOR_EXPR) - return false; - if (range_int_cst_singleton_p (vr1)) - { - if (!range_int_cst_p (vr0)) - return false; - mask = vr1->min; - lower_bound = vr0->min; - upper_bound = vr0->max; - } - else if (range_int_cst_singleton_p (vr0)) - { - if (!range_int_cst_p (vr1)) - return false; - mask = vr0->min; - lower_bound = vr1->min; - upper_bound = vr1->max; - } - else - return false; - if (wide_int_range_can_optimize_bit_op (code, - wi::to_wide (lower_bound), - wi::to_wide (upper_bound), - wi::to_wide (mask))) - { - tree min = int_const_binop (code, lower_bound, mask); - tree max = int_const_binop (code, upper_bound, mask); - set_value_range (vr, VR_RANGE, min, max, NULL); - return true; - } - return false; -} - /* If BOUND will include a symbolic bound, adjust it accordingly, otherwise leave it as is. @@ -1704,9 +1661,6 @@ extract_range_from_binary_expr_1 (value_range *vr, } else if (code == BIT_AND_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR) { - if (vrp_can_optimize_bit_op (vr, code, &vr0, &vr1)) - return; - wide_int may_be_nonzero0, may_be_nonzero1; wide_int must_be_nonzero0, must_be_nonzero1; wide_int wmin, wmax; diff --git a/gcc/wide-int-range.cc b/gcc/wide-int-range.cc index 3cdcede04cda..04d391b33d5e 100644 --- a/gcc/wide-int-range.cc +++ b/gcc/wide-int-range.cc @@ -403,7 +403,7 @@ wide_int_range_lshift (wide_int &res_lb, wide_int &res_ub, It is up to the caller to perform the actual folding above. */ -bool +static bool wide_int_range_can_optimize_bit_op (tree_code code, const wide_int &lb, const wide_int &ub, const wide_int &mask) @@ -443,6 +443,68 @@ wide_int_range_can_optimize_bit_op (tree_code code, return false; } +/* Helper function for wide_int_range_optimize_bit_op. + + Calculates bounds and mask for a pair of ranges. The mask is the + singleton range among the ranges, if any. The bounds are the + bounds for the remaining range. */ + +bool +wide_int_range_get_mask_and_bounds (wide_int &mask, + wide_int &lower_bound, + wide_int &upper_bound, + const wide_int &vr0_min, + const wide_int &vr0_max, + const wide_int &vr1_min, + const wide_int &vr1_max) +{ + if (wi::eq_p (vr1_min, vr1_max)) + { + mask = vr1_min; + lower_bound = vr0_min; + upper_bound = vr0_max; + return true; + } + else if (wi::eq_p (vr0_min, vr0_max)) + { + mask = vr0_min; + lower_bound = vr1_min; + upper_bound = vr1_max; + return true; + } + return false; +} + +/* Optimize a bit operation (BIT_AND_EXPR or BIT_IOR_EXPR) if + possible. If so, return TRUE and store the result in + [RES_LB, RES_UB]. */ + +bool +wide_int_range_optimize_bit_op (wide_int &res_lb, wide_int &res_ub, + enum tree_code code, + signop sign, + const wide_int &vr0_min, + const wide_int &vr0_max, + const wide_int &vr1_min, + const wide_int &vr1_max) +{ + gcc_assert (code == BIT_AND_EXPR || code == BIT_IOR_EXPR); + + wide_int lower_bound, upper_bound, mask; + if (!wide_int_range_get_mask_and_bounds (mask, lower_bound, upper_bound, + vr0_min, vr0_max, vr1_min, vr1_max)) + return false; + if (wide_int_range_can_optimize_bit_op (code, + lower_bound, upper_bound, mask)) + { + wi::overflow_type ovf; + wide_int_binop (res_lb, code, lower_bound, mask, sign, &ovf); + wide_int_binop (res_ub, code, upper_bound, mask, sign, &ovf); + return true; + } + return false; +} + /* Calculate the XOR of two ranges and store the result in [WMIN,WMAX]. The two input ranges are described by their MUST_BE_NONZERO and MAY_BE_NONZERO bit masks. @@ -489,6 +551,10 @@ wide_int_range_bit_ior (wide_int &wmin, wide_int &wmax, const wide_int &must_be_nonzero1, const wide_int &may_be_nonzero1) { + if (wide_int_range_optimize_bit_op (wmin, wmax, BIT_IOR_EXPR, sign, + vr0_min, vr0_max, + vr1_min, vr1_max)) + return true; wmin = must_be_nonzero0 | must_be_nonzero1; wmax = may_be_nonzero0 | may_be_nonzero1; /* If the input ranges contain only positive values we can @@ -530,6 +596,10 @@ wide_int_range_bit_and (wide_int &wmin, wide_int &wmax, const wide_int &must_be_nonzero1, const wide_int &may_be_nonzero1) { + if (wide_int_range_optimize_bit_op (wmin, wmax, BIT_AND_EXPR, sign, + vr0_min, vr0_max, + vr1_min, vr1_max)) + return true; wmin = must_be_nonzero0 & must_be_nonzero1; wmax = may_be_nonzero0 & may_be_nonzero1; /* If both input ranges contain only negative values we can diff --git a/gcc/wide-int-range.h b/gcc/wide-int-range.h index 427ef34c6b4b..eaf47bca4491 100644 --- a/gcc/wide-int-range.h +++ b/gcc/wide-int-range.h @@ -55,10 +55,20 @@ extern void wide_int_range_set_zero_nonzero_bits (signop, const wide_int &ub, wide_int &may_be_nonzero, wide_int &must_be_nonzero); -extern bool wide_int_range_can_optimize_bit_op (tree_code, - const wide_int &lb, - const wide_int &ub, - const wide_int &mask); +extern bool wide_int_range_optimize_bit_op (wide_int &res_lb, wide_int &res_ub, + enum tree_code code, + signop sign, + const wide_int &vr0_lb, + const wide_int &vr0_ub, + const wide_int &vr1_lb, + const wide_int &vr1_ub); +extern bool wide_int_range_get_mask_and_bounds (wide_int &mask, + wide_int &lower_bound, + wide_int &upper_bound, + const wide_int &vr0_min, + const wide_int &vr0_max, + const wide_int &vr1_min, + const wide_int &vr1_max); extern bool wide_int_range_bit_xor (wide_int &wmin, wide_int &wmax, signop sign, unsigned prec,