}
-/* Return 1 if VAL is inside value range VR (VR->MIN <= VAL <= VR->MAX),
- 0 if VAL is not inside VR,
+/* Return 1 if VAL is inside value range MIN <= VAL <= MAX,
+ 0 if VAL is not inside [MIN, MAX],
-2 if we cannot tell either way.
- FIXME, the current semantics of this functions are a bit quirky
- when taken in the context of VRP. In here we do not care
- about VR's type. If VR is the anti-range ~[3, 5] the call
- value_inside_range (4, VR) will return 1.
-
- This is counter-intuitive in a strict sense, but the callers
- currently expect this. They are calling the function
- merely to determine whether VR->MIN <= VAL <= VR->MAX. The
- callers are applying the VR_RANGE/VR_ANTI_RANGE semantics
- themselves.
-
- This also applies to value_ranges_intersect_p and
- range_includes_zero_p. The semantics of VR_RANGE and
- VR_ANTI_RANGE should be encoded here, but that also means
- adapting the users of these functions to the new semantics.
-
Benchmark compile/20001226-1.c compilation time after changing this
function. */
static inline int
-value_inside_range (tree val, value_range_t * vr)
+value_inside_range (tree val, tree min, tree max)
{
int cmp1, cmp2;
- cmp1 = operand_less_p (val, vr->min);
+ cmp1 = operand_less_p (val, min);
if (cmp1 == -2)
return -2;
if (cmp1 == 1)
return 0;
- cmp2 = operand_less_p (vr->max, val);
+ cmp2 = operand_less_p (max, val);
if (cmp2 == -2)
return -2;
}
-/* Return true if VR includes the value zero, false otherwise. FIXME,
- currently this will return false for an anti-range like ~[-4, 3].
- This will be wrong when the semantics of value_inside_range are
- modified (currently the users of this function expect these
- semantics). */
+/* Return 1 if [MIN, MAX] includes the value zero, 0 if it does not
+ include the value zero, -2 if we cannot tell. */
-static inline bool
-range_includes_zero_p (value_range_t *vr)
+static inline int
+range_includes_zero_p (tree min, tree max)
{
- tree zero;
-
- gcc_assert (vr->type != VR_UNDEFINED
- && vr->type != VR_VARYING
- && !symbolic_range_p (vr));
-
- zero = build_int_cst (TREE_TYPE (vr->min), 0);
- return (value_inside_range (zero, vr) == 1);
+ tree zero = build_int_cst (TREE_TYPE (min), 0);
+ return value_inside_range (zero, min, max);
}
/* Return true if *VR is know to only contain nonnegative values. */
gives [min / 4, max / 4] range. */
if (vr1.type == VR_RANGE
&& !symbolic_range_p (&vr1)
- && !range_includes_zero_p (&vr1))
+ && range_includes_zero_p (vr1.min, vr1.max) == 0)
{
vr0.type = type = VR_RANGE;
vr0.min = vrp_val_min (expr_type);
not eliminate a division by zero. */
if (cfun->can_throw_non_call_exceptions
&& (vr1.type != VR_RANGE
- || symbolic_range_p (&vr1)
- || range_includes_zero_p (&vr1)))
+ || range_includes_zero_p (vr1.min, vr1.max) != 0))
{
set_value_range_to_varying (vr);
return;
include 0. */
if (vr0.type == VR_RANGE
&& (vr1.type != VR_RANGE
- || symbolic_range_p (&vr1)
- || range_includes_zero_p (&vr1)))
+ || range_includes_zero_p (vr1.min, vr1.max) != 0))
{
tree zero = build_int_cst (TREE_TYPE (vr0.min), 0);
int cmp;
else if (code == TRUNC_MOD_EXPR)
{
if (vr1.type != VR_RANGE
- || symbolic_range_p (&vr1)
- || range_includes_zero_p (&vr1)
+ || range_includes_zero_p (vr1.min, vr1.max) != 0
|| vrp_val_is_min (vr1.min))
{
set_value_range_to_varying (vr);
~[-INF, min(MIN, MAX)]. */
if (vr0.type == VR_ANTI_RANGE)
{
- if (range_includes_zero_p (&vr0))
+ if (range_includes_zero_p (vr0.min, vr0.max) == 1)
{
/* Take the lower of the two values. */
if (cmp != 1)
/* If the range contains zero then we know that the minimum value in the
range will be zero. */
- else if (range_includes_zero_p (&vr0))
+ else if (range_includes_zero_p (vr0.min, vr0.max) == 1)
{
if (cmp == 1)
max = min;
return NULL_TREE;
/* ~[VAL_1, VAL_2] OP VAL is known if VAL_1 <= VAL <= VAL_2. */
- if (value_inside_range (val, vr) == 1)
+ if (value_inside_range (val, vr->min, vr->max) == 1)
return (comp == NE_EXPR) ? boolean_true_node : boolean_false_node;
return NULL_TREE;
anti-range. FIXME, all this nonsense about distinguishing
anti-ranges from ranges is necessary because of the odd
semantics of range_includes_zero_p and friends. */
- if (!symbolic_range_p (&saved)
- && ((saved.type == VR_RANGE && !range_includes_zero_p (&saved))
- || (saved.type == VR_ANTI_RANGE && range_includes_zero_p (&saved)))
- && !symbolic_range_p (vr1)
- && ((vr1->type == VR_RANGE && !range_includes_zero_p (vr1))
- || (vr1->type == VR_ANTI_RANGE && range_includes_zero_p (vr1))))
+ if (((saved.type == VR_RANGE
+ && range_includes_zero_p (saved.min, saved.max) == 0)
+ || (saved.type == VR_ANTI_RANGE
+ && range_includes_zero_p (saved.min, saved.max) == 1))
+ && ((vr1->type == VR_RANGE
+ && range_includes_zero_p (vr1->min, vr1->max) == 0)
+ || (vr1->type == VR_ANTI_RANGE
+ && range_includes_zero_p (vr1->min, vr1->max) == 1)))
{
set_value_range_to_nonnull (vr0, TREE_TYPE (saved.min));