Fix swapping of ranges.

The legacy range code has logic to swap out of order endpoints in the
irange constructor.  The new irange code expects the caller to fix any
inconsistencies, thus speeding up the common case.  However, this means
that when we remove legacy, any stragglers must be fixed.  This patch
fixes the 3 culprits found during the conversion.

gcc/ChangeLog:

	* range-op.cc (operator_cast::op1_range): Use
	create_possibly_reversed_range.
	(operator_bitwise_and::simple_op1_range_solver): Same.
	* value-range.cc (swap_out_of_order_endpoints): Delete.
	(irange::set): Remove call to swap_out_of_order_endpoints.
This commit is contained in:
Aldy Hernandez 2022-12-21 19:26:00 +01:00
parent 5bdc515513
commit 04e5ddf8a3
2 changed files with 6 additions and 51 deletions

View file

@ -2876,8 +2876,9 @@ operator_cast::op1_range (irange &r, tree type,
// Start by building the positive signed outer range for the type.
wide_int lim = wi::set_bit_in_zero (TYPE_PRECISION (lhs_type),
TYPE_PRECISION (type));
r = int_range<1> (type, lim, wi::max_value (TYPE_PRECISION (type),
SIGNED));
create_possibly_reversed_range (r, type, lim,
wi::max_value (TYPE_PRECISION (type),
SIGNED));
// For the signed part, we need to simply union the 2 ranges now.
r.union_ (converted_lhs);
@ -3367,7 +3368,7 @@ operator_bitwise_and::simple_op1_range_solver (irange &r, tree type,
if (we_know_nothing)
r.set_varying (type);
else
r = int_range<1> (type, minv, maxv);
create_possibly_reversed_range (r, type, minv, maxv);
// Solve [-INF, lhs.upper_bound ()] = x & MASK.
//
@ -3398,7 +3399,8 @@ operator_bitwise_and::simple_op1_range_solver (irange &r, tree type,
}
maxv |= ~cst2v;
minv = sgnbit;
int_range<1> upper_bits (type, minv, maxv);
int_range<2> upper_bits;
create_possibly_reversed_range (upper_bits, type, minv, maxv);
r.intersect (upper_bits);
}

View file

@ -1014,46 +1014,6 @@ irange::copy_to_legacy (const irange &src)
set (src.tree_lower_bound (), src.tree_upper_bound ());
}
// Swap MIN/MAX if they are out of order and adjust KIND appropriately.
static void
swap_out_of_order_endpoints (tree &min, tree &max, value_range_kind &kind)
{
gcc_checking_assert (kind != VR_UNDEFINED);
if (kind == VR_VARYING)
return;
/* Wrong order for min and max, to swap them and the VR type we need
to adjust them. */
if (tree_int_cst_lt (max, min))
{
tree one, tmp;
/* For one bit precision if max < min, then the swapped
range covers all values, so for VR_RANGE it is varying and
for VR_ANTI_RANGE empty range, so drop to varying as well. */
if (TYPE_PRECISION (TREE_TYPE (min)) == 1)
{
kind = VR_VARYING;
return;
}
one = build_int_cst (TREE_TYPE (min), 1);
tmp = int_const_binop (PLUS_EXPR, max, one);
max = int_const_binop (MINUS_EXPR, min, one);
min = tmp;
/* There's one corner case, if we had [C+1, C] before we now have
that again. But this represents an empty value range, so drop
to varying in this case. */
if (tree_int_cst_lt (max, min))
{
kind = VR_VARYING;
return;
}
kind = kind == VR_RANGE ? VR_ANTI_RANGE : VR_RANGE;
}
}
void
irange::irange_set (tree min, tree max)
{
@ -1192,13 +1152,6 @@ irange::set (tree min, tree max, value_range_kind kind)
gcc_checking_assert (TREE_CODE (min) == INTEGER_CST
&& TREE_CODE (max) == INTEGER_CST);
swap_out_of_order_endpoints (min, max, kind);
if (kind == VR_VARYING)
{
set_varying (TREE_TYPE (min));
return;
}
// Anti-ranges that can be represented as ranges should be so.
if (kind == VR_ANTI_RANGE)
{