1 /* Code for range operators.
2 Copyright (C) 2017-2022 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4 and Aldy Hernandez <aldyh@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
26 #include "insn-codes.h"
31 #include "tree-pass.h"
33 #include "optabs-tree.h"
34 #include "gimple-pretty-print.h"
35 #include "diagnostic-core.h"
37 #include "fold-const.h"
38 #include "stor-layout.h"
41 #include "gimple-iterator.h"
42 #include "gimple-fold.h"
44 #include "gimple-walk.h"
47 #include "value-relation.h"
50 // Return the upper limit for a type.
52 static inline wide_int
53 max_limit (const_tree type
)
55 return wi::max_value (TYPE_PRECISION (type
) , TYPE_SIGN (type
));
58 // Return the lower limit for a type.
60 static inline wide_int
61 min_limit (const_tree type
)
63 return wi::min_value (TYPE_PRECISION (type
) , TYPE_SIGN (type
));
66 // Return false if shifting by OP is undefined behavior. Otherwise, return
67 // true and the range it is to be shifted by. This allows trimming out of
68 // undefined ranges, leaving only valid ranges if there are any.
71 get_shift_range (irange
&r
, tree type
, const irange
&op
)
73 if (op
.undefined_p ())
76 // Build valid range and intersect it with the shift range.
77 r
= value_range (build_int_cst_type (op
.type (), 0),
78 build_int_cst_type (op
.type (), TYPE_PRECISION (type
) - 1));
81 // If there are no valid ranges in the shift range, returned false.
87 // Return TRUE if 0 is within [WMIN, WMAX].
90 wi_includes_zero_p (tree type
, const wide_int
&wmin
, const wide_int
&wmax
)
92 signop sign
= TYPE_SIGN (type
);
93 return wi::le_p (wmin
, 0, sign
) && wi::ge_p (wmax
, 0, sign
);
96 // Return TRUE if [WMIN, WMAX] is the singleton 0.
99 wi_zero_p (tree type
, const wide_int
&wmin
, const wide_int
&wmax
)
101 unsigned prec
= TYPE_PRECISION (type
);
102 return wmin
== wmax
&& wi::eq_p (wmin
, wi::zero (prec
));
105 // Default wide_int fold operation returns [MIN, MAX].
108 range_operator::wi_fold (irange
&r
, tree type
,
109 const wide_int
&lh_lb ATTRIBUTE_UNUSED
,
110 const wide_int
&lh_ub ATTRIBUTE_UNUSED
,
111 const wide_int
&rh_lb ATTRIBUTE_UNUSED
,
112 const wide_int
&rh_ub ATTRIBUTE_UNUSED
) const
114 gcc_checking_assert (r
.supports_type_p (type
));
115 r
.set_varying (type
);
118 // Call wi_fold, except further split small subranges into constants.
119 // This can provide better precision. For something 8 >> [0,1]
120 // Instead of [8, 16], we will produce [8,8][16,16]
123 range_operator::wi_fold_in_parts (irange
&r
, tree type
,
124 const wide_int
&lh_lb
,
125 const wide_int
&lh_ub
,
126 const wide_int
&rh_lb
,
127 const wide_int
&rh_ub
) const
130 widest_int rh_range
= wi::sub (widest_int::from (rh_ub
, TYPE_SIGN (type
)),
131 widest_int::from (rh_lb
, TYPE_SIGN (type
)));
132 widest_int lh_range
= wi::sub (widest_int::from (lh_ub
, TYPE_SIGN (type
)),
133 widest_int::from (lh_lb
, TYPE_SIGN (type
)));
134 // If there are 2, 3, or 4 values in the RH range, do them separately.
135 // Call wi_fold_in_parts to check the RH side.
136 if (rh_range
> 0 && rh_range
< 4)
138 wi_fold_in_parts (r
, type
, lh_lb
, lh_ub
, rh_lb
, rh_lb
);
141 wi_fold_in_parts (tmp
, type
, lh_lb
, lh_ub
, rh_lb
+ 1, rh_lb
+ 1);
145 wi_fold_in_parts (tmp
, type
, lh_lb
, lh_ub
, rh_lb
+ 2, rh_lb
+ 2);
149 wi_fold_in_parts (tmp
, type
, lh_lb
, lh_ub
, rh_ub
, rh_ub
);
152 // Otherise check for 2, 3, or 4 values in the LH range and split them up.
153 // The RH side has been checked, so no recursion needed.
154 else if (lh_range
> 0 && lh_range
< 4)
156 wi_fold (r
, type
, lh_lb
, lh_lb
, rh_lb
, rh_ub
);
159 wi_fold (tmp
, type
, lh_lb
+ 1, lh_lb
+ 1, rh_lb
, rh_ub
);
163 wi_fold (tmp
, type
, lh_lb
+ 2, lh_lb
+ 2, rh_lb
, rh_ub
);
167 wi_fold (tmp
, type
, lh_ub
, lh_ub
, rh_lb
, rh_ub
);
170 // Otherwise just call wi_fold.
172 wi_fold (r
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
);
175 // The default for fold is to break all ranges into sub-ranges and
176 // invoke the wi_fold method on each sub-range pair.
179 range_operator::fold_range (irange
&r
, tree type
,
182 relation_kind rel
) const
184 gcc_checking_assert (r
.supports_type_p (type
));
185 if (empty_range_varying (r
, type
, lh
, rh
))
188 unsigned num_lh
= lh
.num_pairs ();
189 unsigned num_rh
= rh
.num_pairs ();
191 // If both ranges are single pairs, fold directly into the result range.
192 // If the number of subranges grows too high, produce a summary result as the
193 // loop becomes exponential with little benefit. See PR 103821.
194 if ((num_lh
== 1 && num_rh
== 1) || num_lh
* num_rh
> 12)
196 wi_fold_in_parts (r
, type
, lh
.lower_bound (), lh
.upper_bound (),
197 rh
.lower_bound (), rh
.upper_bound ());
198 op1_op2_relation_effect (r
, type
, lh
, rh
, rel
);
204 for (unsigned x
= 0; x
< num_lh
; ++x
)
205 for (unsigned y
= 0; y
< num_rh
; ++y
)
207 wide_int lh_lb
= lh
.lower_bound (x
);
208 wide_int lh_ub
= lh
.upper_bound (x
);
209 wide_int rh_lb
= rh
.lower_bound (y
);
210 wide_int rh_ub
= rh
.upper_bound (y
);
211 wi_fold_in_parts (tmp
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
);
215 op1_op2_relation_effect (r
, type
, lh
, rh
, rel
);
219 op1_op2_relation_effect (r
, type
, lh
, rh
, rel
);
223 // The default for op1_range is to return false.
226 range_operator::op1_range (irange
&r ATTRIBUTE_UNUSED
,
227 tree type ATTRIBUTE_UNUSED
,
228 const irange
&lhs ATTRIBUTE_UNUSED
,
229 const irange
&op2 ATTRIBUTE_UNUSED
,
230 relation_kind rel ATTRIBUTE_UNUSED
) const
235 // The default for op2_range is to return false.
238 range_operator::op2_range (irange
&r ATTRIBUTE_UNUSED
,
239 tree type ATTRIBUTE_UNUSED
,
240 const irange
&lhs ATTRIBUTE_UNUSED
,
241 const irange
&op1 ATTRIBUTE_UNUSED
,
242 relation_kind rel ATTRIBUTE_UNUSED
) const
247 // The default relation routines return VREL_VARYING.
250 range_operator::lhs_op1_relation (const irange
&lhs ATTRIBUTE_UNUSED
,
251 const irange
&op1 ATTRIBUTE_UNUSED
,
252 const irange
&op2 ATTRIBUTE_UNUSED
,
253 relation_kind rel ATTRIBUTE_UNUSED
) const
259 range_operator::lhs_op2_relation (const irange
&lhs ATTRIBUTE_UNUSED
,
260 const irange
&op1 ATTRIBUTE_UNUSED
,
261 const irange
&op2 ATTRIBUTE_UNUSED
,
262 relation_kind rel ATTRIBUTE_UNUSED
) const
268 range_operator::op1_op2_relation (const irange
&lhs ATTRIBUTE_UNUSED
) const
273 // Default is no relation affects the LHS.
276 range_operator::op1_op2_relation_effect (irange
&lhs_range ATTRIBUTE_UNUSED
,
277 tree type ATTRIBUTE_UNUSED
,
278 const irange
&op1_range ATTRIBUTE_UNUSED
,
279 const irange
&op2_range ATTRIBUTE_UNUSED
,
280 relation_kind rel ATTRIBUTE_UNUSED
) const
285 // Create and return a range from a pair of wide-ints that are known
286 // to have overflowed (or underflowed).
289 value_range_from_overflowed_bounds (irange
&r
, tree type
,
290 const wide_int
&wmin
,
291 const wide_int
&wmax
)
293 const signop sgn
= TYPE_SIGN (type
);
294 const unsigned int prec
= TYPE_PRECISION (type
);
296 wide_int tmin
= wide_int::from (wmin
, prec
, sgn
);
297 wide_int tmax
= wide_int::from (wmax
, prec
, sgn
);
302 if (wi::cmp (tmin
, tmax
, sgn
) < 0)
305 if (wi::cmp (tmax
, tem
, sgn
) > 0)
308 // If the anti-range would cover nothing, drop to varying.
309 // Likewise if the anti-range bounds are outside of the types
311 if (covers
|| wi::cmp (tmin
, tmax
, sgn
) > 0)
312 r
.set_varying (type
);
315 tree tree_min
= wide_int_to_tree (type
, tmin
);
316 tree tree_max
= wide_int_to_tree (type
, tmax
);
317 r
.set (tree_min
, tree_max
, VR_ANTI_RANGE
);
321 // Create and return a range from a pair of wide-ints. MIN_OVF and
322 // MAX_OVF describe any overflow that might have occurred while
323 // calculating WMIN and WMAX respectively.
326 value_range_with_overflow (irange
&r
, tree type
,
327 const wide_int
&wmin
, const wide_int
&wmax
,
328 wi::overflow_type min_ovf
= wi::OVF_NONE
,
329 wi::overflow_type max_ovf
= wi::OVF_NONE
)
331 const signop sgn
= TYPE_SIGN (type
);
332 const unsigned int prec
= TYPE_PRECISION (type
);
333 const bool overflow_wraps
= TYPE_OVERFLOW_WRAPS (type
);
335 // For one bit precision if max != min, then the range covers all
337 if (prec
== 1 && wi::ne_p (wmax
, wmin
))
339 r
.set_varying (type
);
345 // If overflow wraps, truncate the values and adjust the range,
346 // kind, and bounds appropriately.
347 if ((min_ovf
!= wi::OVF_NONE
) == (max_ovf
!= wi::OVF_NONE
))
349 wide_int tmin
= wide_int::from (wmin
, prec
, sgn
);
350 wide_int tmax
= wide_int::from (wmax
, prec
, sgn
);
351 // If the limits are swapped, we wrapped around and cover
353 if (wi::gt_p (tmin
, tmax
, sgn
))
354 r
.set_varying (type
);
356 // No overflow or both overflow or underflow. The range
357 // kind stays normal.
358 r
.set (wide_int_to_tree (type
, tmin
),
359 wide_int_to_tree (type
, tmax
));
363 if ((min_ovf
== wi::OVF_UNDERFLOW
&& max_ovf
== wi::OVF_NONE
)
364 || (max_ovf
== wi::OVF_OVERFLOW
&& min_ovf
== wi::OVF_NONE
))
365 value_range_from_overflowed_bounds (r
, type
, wmin
, wmax
);
367 // Other underflow and/or overflow, drop to VR_VARYING.
368 r
.set_varying (type
);
372 // If both bounds either underflowed or overflowed, then the result
374 if ((min_ovf
== wi::OVF_OVERFLOW
&& max_ovf
== wi::OVF_OVERFLOW
)
375 || (min_ovf
== wi::OVF_UNDERFLOW
&& max_ovf
== wi::OVF_UNDERFLOW
))
381 // If overflow does not wrap, saturate to [MIN, MAX].
382 wide_int new_lb
, new_ub
;
383 if (min_ovf
== wi::OVF_UNDERFLOW
)
384 new_lb
= wi::min_value (prec
, sgn
);
385 else if (min_ovf
== wi::OVF_OVERFLOW
)
386 new_lb
= wi::max_value (prec
, sgn
);
390 if (max_ovf
== wi::OVF_UNDERFLOW
)
391 new_ub
= wi::min_value (prec
, sgn
);
392 else if (max_ovf
== wi::OVF_OVERFLOW
)
393 new_ub
= wi::max_value (prec
, sgn
);
397 r
.set (wide_int_to_tree (type
, new_lb
),
398 wide_int_to_tree (type
, new_ub
));
402 // Create and return a range from a pair of wide-ints. Canonicalize
403 // the case where the bounds are swapped. In which case, we transform
404 // [10,5] into [MIN,5][10,MAX].
407 create_possibly_reversed_range (irange
&r
, tree type
,
408 const wide_int
&new_lb
, const wide_int
&new_ub
)
410 signop s
= TYPE_SIGN (type
);
411 // If the bounds are swapped, treat the result as if an overflow occured.
412 if (wi::gt_p (new_lb
, new_ub
, s
))
413 value_range_from_overflowed_bounds (r
, type
, new_lb
, new_ub
);
415 // Otherwise it's just a normal range.
416 r
.set (wide_int_to_tree (type
, new_lb
), wide_int_to_tree (type
, new_ub
));
419 // Return the summary information about boolean range LHS. If EMPTY/FULL,
420 // return the equivalent range for TYPE in R; if FALSE/TRUE, do nothing.
423 get_bool_state (vrange
&r
, const vrange
&lhs
, tree val_type
)
425 // If there is no result, then this is unexecutable.
426 if (lhs
.undefined_p ())
435 // For TRUE, we can't just test for [1,1] because Ada can have
436 // multi-bit booleans, and TRUE values can be: [1, MAX], ~[0], etc.
437 if (lhs
.contains_p (build_zero_cst (lhs
.type ())))
439 r
.set_varying (val_type
);
447 class operator_equal
: public range_operator
449 using range_operator::fold_range
;
450 using range_operator::op1_range
;
451 using range_operator::op2_range
;
453 virtual bool fold_range (irange
&r
, tree type
,
456 relation_kind rel
= VREL_VARYING
) const;
457 virtual bool op1_range (irange
&r
, tree type
,
460 relation_kind rel
= VREL_VARYING
) const;
461 virtual bool op2_range (irange
&r
, tree type
,
464 relation_kind rel
= VREL_VARYING
) const;
465 virtual relation_kind
op1_op2_relation (const irange
&lhs
) const;
468 // Check if the LHS range indicates a relation between OP1 and OP2.
471 equal_op1_op2_relation (const irange
&lhs
)
473 if (lhs
.undefined_p ())
474 return VREL_UNDEFINED
;
476 // FALSE = op1 == op2 indicates NE_EXPR.
480 // TRUE = op1 == op2 indicates EQ_EXPR.
481 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
487 operator_equal::op1_op2_relation (const irange
&lhs
) const
489 return equal_op1_op2_relation (lhs
);
494 operator_equal::fold_range (irange
&r
, tree type
,
497 relation_kind rel
) const
499 if (relop_early_resolve (r
, type
, op1
, op2
, rel
, VREL_EQ
))
502 // We can be sure the values are always equal or not if both ranges
503 // consist of a single value, and then compare them.
504 if (wi::eq_p (op1
.lower_bound (), op1
.upper_bound ())
505 && wi::eq_p (op2
.lower_bound (), op2
.upper_bound ()))
507 if (wi::eq_p (op1
.lower_bound (), op2
.upper_bound()))
508 r
= range_true (type
);
510 r
= range_false (type
);
514 // If ranges do not intersect, we know the range is not equal,
515 // otherwise we don't know anything for sure.
516 int_range_max tmp
= op1
;
518 if (tmp
.undefined_p ())
519 r
= range_false (type
);
521 r
= range_true_and_false (type
);
527 operator_equal::op1_range (irange
&r
, tree type
,
530 relation_kind rel ATTRIBUTE_UNUSED
) const
532 switch (get_bool_state (r
, lhs
, type
))
535 // If the result is false, the only time we know anything is
536 // if OP2 is a constant.
537 if (wi::eq_p (op2
.lower_bound(), op2
.upper_bound()))
543 r
.set_varying (type
);
547 // If it's true, the result is the same as OP2.
558 operator_equal::op2_range (irange
&r
, tree type
,
561 relation_kind rel
) const
563 return operator_equal::op1_range (r
, type
, lhs
, op1
, rel
);
566 class operator_not_equal
: public range_operator
568 using range_operator::fold_range
;
569 using range_operator::op1_range
;
570 using range_operator::op2_range
;
572 virtual bool fold_range (irange
&r
, tree type
,
575 relation_kind rel
= VREL_VARYING
) const;
576 virtual bool op1_range (irange
&r
, tree type
,
579 relation_kind rel
= VREL_VARYING
) const;
580 virtual bool op2_range (irange
&r
, tree type
,
583 relation_kind rel
= VREL_VARYING
) const;
584 virtual relation_kind
op1_op2_relation (const irange
&lhs
) const;
587 // Check if the LHS range indicates a relation between OP1 and OP2.
590 not_equal_op1_op2_relation (const irange
&lhs
)
592 if (lhs
.undefined_p ())
593 return VREL_UNDEFINED
;
595 // FALSE = op1 != op2 indicates EQ_EXPR.
599 // TRUE = op1 != op2 indicates NE_EXPR.
600 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
606 operator_not_equal::op1_op2_relation (const irange
&lhs
) const
608 return not_equal_op1_op2_relation (lhs
);
612 operator_not_equal::fold_range (irange
&r
, tree type
,
615 relation_kind rel
) const
617 if (relop_early_resolve (r
, type
, op1
, op2
, rel
, VREL_NE
))
620 // We can be sure the values are always equal or not if both ranges
621 // consist of a single value, and then compare them.
622 if (wi::eq_p (op1
.lower_bound (), op1
.upper_bound ())
623 && wi::eq_p (op2
.lower_bound (), op2
.upper_bound ()))
625 if (wi::ne_p (op1
.lower_bound (), op2
.upper_bound()))
626 r
= range_true (type
);
628 r
= range_false (type
);
632 // If ranges do not intersect, we know the range is not equal,
633 // otherwise we don't know anything for sure.
634 int_range_max tmp
= op1
;
636 if (tmp
.undefined_p ())
637 r
= range_true (type
);
639 r
= range_true_and_false (type
);
645 operator_not_equal::op1_range (irange
&r
, tree type
,
648 relation_kind rel ATTRIBUTE_UNUSED
) const
650 switch (get_bool_state (r
, lhs
, type
))
653 // If the result is true, the only time we know anything is if
654 // OP2 is a constant.
655 if (wi::eq_p (op2
.lower_bound(), op2
.upper_bound()))
661 r
.set_varying (type
);
665 // If it's false, the result is the same as OP2.
677 operator_not_equal::op2_range (irange
&r
, tree type
,
680 relation_kind rel
) const
682 return operator_not_equal::op1_range (r
, type
, lhs
, op1
, rel
);
685 // (X < VAL) produces the range of [MIN, VAL - 1].
688 build_lt (irange
&r
, tree type
, const wide_int
&val
)
690 wi::overflow_type ov
;
692 signop sgn
= TYPE_SIGN (type
);
694 // Signed 1 bit cannot represent 1 for subtraction.
696 lim
= wi::add (val
, -1, sgn
, &ov
);
698 lim
= wi::sub (val
, 1, sgn
, &ov
);
700 // If val - 1 underflows, check if X < MIN, which is an empty range.
704 r
= int_range
<1> (type
, min_limit (type
), lim
);
707 // (X <= VAL) produces the range of [MIN, VAL].
710 build_le (irange
&r
, tree type
, const wide_int
&val
)
712 r
= int_range
<1> (type
, min_limit (type
), val
);
715 // (X > VAL) produces the range of [VAL + 1, MAX].
718 build_gt (irange
&r
, tree type
, const wide_int
&val
)
720 wi::overflow_type ov
;
722 signop sgn
= TYPE_SIGN (type
);
724 // Signed 1 bit cannot represent 1 for addition.
726 lim
= wi::sub (val
, -1, sgn
, &ov
);
728 lim
= wi::add (val
, 1, sgn
, &ov
);
729 // If val + 1 overflows, check is for X > MAX, which is an empty range.
733 r
= int_range
<1> (type
, lim
, max_limit (type
));
736 // (X >= val) produces the range of [VAL, MAX].
739 build_ge (irange
&r
, tree type
, const wide_int
&val
)
741 r
= int_range
<1> (type
, val
, max_limit (type
));
745 class operator_lt
: public range_operator
747 using range_operator::fold_range
;
748 using range_operator::op1_range
;
749 using range_operator::op2_range
;
751 virtual bool fold_range (irange
&r
, tree type
,
754 relation_kind rel
= VREL_VARYING
) const;
755 virtual bool op1_range (irange
&r
, tree type
,
758 relation_kind rel
= VREL_VARYING
) const;
759 virtual bool op2_range (irange
&r
, tree type
,
762 relation_kind rel
= VREL_VARYING
) const;
763 virtual relation_kind
op1_op2_relation (const irange
&lhs
) const;
766 // Check if the LHS range indicates a relation between OP1 and OP2.
769 lt_op1_op2_relation (const irange
&lhs
)
771 if (lhs
.undefined_p ())
772 return VREL_UNDEFINED
;
774 // FALSE = op1 < op2 indicates GE_EXPR.
778 // TRUE = op1 < op2 indicates LT_EXPR.
779 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
785 operator_lt::op1_op2_relation (const irange
&lhs
) const
787 return lt_op1_op2_relation (lhs
);
791 operator_lt::fold_range (irange
&r
, tree type
,
794 relation_kind rel
) const
796 if (relop_early_resolve (r
, type
, op1
, op2
, rel
, VREL_LT
))
799 signop sign
= TYPE_SIGN (op1
.type ());
800 gcc_checking_assert (sign
== TYPE_SIGN (op2
.type ()));
802 if (wi::lt_p (op1
.upper_bound (), op2
.lower_bound (), sign
))
803 r
= range_true (type
);
804 else if (!wi::lt_p (op1
.lower_bound (), op2
.upper_bound (), sign
))
805 r
= range_false (type
);
807 r
= range_true_and_false (type
);
812 operator_lt::op1_range (irange
&r
, tree type
,
815 relation_kind rel ATTRIBUTE_UNUSED
) const
817 switch (get_bool_state (r
, lhs
, type
))
820 build_lt (r
, type
, op2
.upper_bound ());
824 build_ge (r
, type
, op2
.lower_bound ());
834 operator_lt::op2_range (irange
&r
, tree type
,
837 relation_kind rel ATTRIBUTE_UNUSED
) const
839 switch (get_bool_state (r
, lhs
, type
))
842 build_le (r
, type
, op1
.upper_bound ());
846 build_gt (r
, type
, op1
.lower_bound ());
856 class operator_le
: public range_operator
858 using range_operator::fold_range
;
859 using range_operator::op1_range
;
860 using range_operator::op2_range
;
862 virtual bool fold_range (irange
&r
, tree type
,
865 relation_kind rel
= VREL_VARYING
) const;
866 virtual bool op1_range (irange
&r
, tree type
,
869 relation_kind rel
= VREL_VARYING
) const;
870 virtual bool op2_range (irange
&r
, tree type
,
873 relation_kind rel
= VREL_VARYING
) const;
874 virtual relation_kind
op1_op2_relation (const irange
&lhs
) const;
877 // Check if the LHS range indicates a relation between OP1 and OP2.
880 le_op1_op2_relation (const irange
&lhs
)
882 if (lhs
.undefined_p ())
883 return VREL_UNDEFINED
;
885 // FALSE = op1 <= op2 indicates GT_EXPR.
889 // TRUE = op1 <= op2 indicates LE_EXPR.
890 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
896 operator_le::op1_op2_relation (const irange
&lhs
) const
898 return le_op1_op2_relation (lhs
);
902 operator_le::fold_range (irange
&r
, tree type
,
905 relation_kind rel
) const
907 if (relop_early_resolve (r
, type
, op1
, op2
, rel
, VREL_LE
))
910 signop sign
= TYPE_SIGN (op1
.type ());
911 gcc_checking_assert (sign
== TYPE_SIGN (op2
.type ()));
913 if (wi::le_p (op1
.upper_bound (), op2
.lower_bound (), sign
))
914 r
= range_true (type
);
915 else if (!wi::le_p (op1
.lower_bound (), op2
.upper_bound (), sign
))
916 r
= range_false (type
);
918 r
= range_true_and_false (type
);
923 operator_le::op1_range (irange
&r
, tree type
,
926 relation_kind rel ATTRIBUTE_UNUSED
) const
928 switch (get_bool_state (r
, lhs
, type
))
931 build_le (r
, type
, op2
.upper_bound ());
935 build_gt (r
, type
, op2
.lower_bound ());
945 operator_le::op2_range (irange
&r
, tree type
,
948 relation_kind rel ATTRIBUTE_UNUSED
) const
950 switch (get_bool_state (r
, lhs
, type
))
953 build_lt (r
, type
, op1
.upper_bound ());
957 build_ge (r
, type
, op1
.lower_bound ());
967 class operator_gt
: public range_operator
969 using range_operator::fold_range
;
970 using range_operator::op1_range
;
971 using range_operator::op2_range
;
973 virtual bool fold_range (irange
&r
, tree type
,
976 relation_kind rel
= VREL_VARYING
) const;
977 virtual bool op1_range (irange
&r
, tree type
,
980 relation_kind rel
= VREL_VARYING
) const;
981 virtual bool op2_range (irange
&r
, tree type
,
984 relation_kind rel
= VREL_VARYING
) const;
985 virtual relation_kind
op1_op2_relation (const irange
&lhs
) const;
988 // Check if the LHS range indicates a relation between OP1 and OP2.
991 gt_op1_op2_relation (const irange
&lhs
)
993 if (lhs
.undefined_p ())
994 return VREL_UNDEFINED
;
996 // FALSE = op1 > op2 indicates LE_EXPR.
1000 // TRUE = op1 > op2 indicates GT_EXPR.
1001 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
1003 return VREL_VARYING
;
1007 operator_gt::op1_op2_relation (const irange
&lhs
) const
1009 return gt_op1_op2_relation (lhs
);
1014 operator_gt::fold_range (irange
&r
, tree type
,
1015 const irange
&op1
, const irange
&op2
,
1016 relation_kind rel
) const
1018 if (relop_early_resolve (r
, type
, op1
, op2
, rel
, VREL_GT
))
1021 signop sign
= TYPE_SIGN (op1
.type ());
1022 gcc_checking_assert (sign
== TYPE_SIGN (op2
.type ()));
1024 if (wi::gt_p (op1
.lower_bound (), op2
.upper_bound (), sign
))
1025 r
= range_true (type
);
1026 else if (!wi::gt_p (op1
.upper_bound (), op2
.lower_bound (), sign
))
1027 r
= range_false (type
);
1029 r
= range_true_and_false (type
);
1034 operator_gt::op1_range (irange
&r
, tree type
,
1035 const irange
&lhs
, const irange
&op2
,
1036 relation_kind rel ATTRIBUTE_UNUSED
) const
1038 switch (get_bool_state (r
, lhs
, type
))
1041 build_gt (r
, type
, op2
.lower_bound ());
1045 build_le (r
, type
, op2
.upper_bound ());
1055 operator_gt::op2_range (irange
&r
, tree type
,
1058 relation_kind rel ATTRIBUTE_UNUSED
) const
1060 switch (get_bool_state (r
, lhs
, type
))
1063 build_ge (r
, type
, op1
.lower_bound ());
1067 build_lt (r
, type
, op1
.upper_bound ());
1077 class operator_ge
: public range_operator
1079 using range_operator::fold_range
;
1080 using range_operator::op1_range
;
1081 using range_operator::op2_range
;
1083 virtual bool fold_range (irange
&r
, tree type
,
1086 relation_kind rel
= VREL_VARYING
) const;
1087 virtual bool op1_range (irange
&r
, tree type
,
1090 relation_kind rel
= VREL_VARYING
) const;
1091 virtual bool op2_range (irange
&r
, tree type
,
1094 relation_kind rel
= VREL_VARYING
) const;
1095 virtual relation_kind
op1_op2_relation (const irange
&lhs
) const;
1098 // Check if the LHS range indicates a relation between OP1 and OP2.
1101 ge_op1_op2_relation (const irange
&lhs
)
1103 if (lhs
.undefined_p ())
1104 return VREL_UNDEFINED
;
1106 // FALSE = op1 >= op2 indicates LT_EXPR.
1110 // TRUE = op1 >= op2 indicates GE_EXPR.
1111 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
1113 return VREL_VARYING
;
1117 operator_ge::op1_op2_relation (const irange
&lhs
) const
1119 return ge_op1_op2_relation (lhs
);
1123 operator_ge::fold_range (irange
&r
, tree type
,
1126 relation_kind rel
) const
1128 if (relop_early_resolve (r
, type
, op1
, op2
, rel
, VREL_GE
))
1131 signop sign
= TYPE_SIGN (op1
.type ());
1132 gcc_checking_assert (sign
== TYPE_SIGN (op2
.type ()));
1134 if (wi::ge_p (op1
.lower_bound (), op2
.upper_bound (), sign
))
1135 r
= range_true (type
);
1136 else if (!wi::ge_p (op1
.upper_bound (), op2
.lower_bound (), sign
))
1137 r
= range_false (type
);
1139 r
= range_true_and_false (type
);
1144 operator_ge::op1_range (irange
&r
, tree type
,
1147 relation_kind rel ATTRIBUTE_UNUSED
) const
1149 switch (get_bool_state (r
, lhs
, type
))
1152 build_ge (r
, type
, op2
.lower_bound ());
1156 build_lt (r
, type
, op2
.upper_bound ());
1166 operator_ge::op2_range (irange
&r
, tree type
,
1169 relation_kind rel ATTRIBUTE_UNUSED
) const
1171 switch (get_bool_state (r
, lhs
, type
))
1174 build_gt (r
, type
, op1
.lower_bound ());
1178 build_le (r
, type
, op1
.upper_bound ());
1188 class operator_plus
: public range_operator
1190 using range_operator::op1_range
;
1191 using range_operator::op2_range
;
1192 using range_operator::lhs_op1_relation
;
1193 using range_operator::lhs_op2_relation
;
1195 virtual bool op1_range (irange
&r
, tree type
,
1198 relation_kind rel ATTRIBUTE_UNUSED
) const;
1199 virtual bool op2_range (irange
&r
, tree type
,
1202 relation_kind rel ATTRIBUTE_UNUSED
) const;
1203 virtual void wi_fold (irange
&r
, tree type
,
1204 const wide_int
&lh_lb
,
1205 const wide_int
&lh_ub
,
1206 const wide_int
&rh_lb
,
1207 const wide_int
&rh_ub
) const;
1208 virtual relation_kind
lhs_op1_relation (const irange
&lhs
, const irange
&op1
,
1210 relation_kind rel
) const;
1211 virtual relation_kind
lhs_op2_relation (const irange
&lhs
, const irange
&op1
,
1213 relation_kind rel
) const;
1216 // Check to see if the range of OP2 indicates anything about the relation
1217 // between LHS and OP1.
1220 operator_plus::lhs_op1_relation (const irange
&lhs
,
1223 relation_kind
) const
1225 if (lhs
.undefined_p () || op1
.undefined_p () || op2
.undefined_p ())
1226 return VREL_VARYING
;
1228 tree type
= lhs
.type ();
1229 unsigned prec
= TYPE_PRECISION (type
);
1230 wi::overflow_type ovf1
, ovf2
;
1231 signop sign
= TYPE_SIGN (type
);
1233 // LHS = OP1 + 0 indicates LHS == OP1.
1237 if (TYPE_OVERFLOW_WRAPS (type
))
1239 wi::add (op1
.lower_bound (), op2
.lower_bound (), sign
, &ovf1
);
1240 wi::add (op1
.upper_bound (), op2
.upper_bound (), sign
, &ovf2
);
1243 ovf1
= ovf2
= wi::OVF_NONE
;
1245 // Never wrapping additions.
1248 // Positive op2 means lhs > op1.
1249 if (wi::gt_p (op2
.lower_bound (), wi::zero (prec
), sign
))
1251 if (wi::ge_p (op2
.lower_bound (), wi::zero (prec
), sign
))
1254 // Negative op2 means lhs < op1.
1255 if (wi::lt_p (op2
.upper_bound (), wi::zero (prec
), sign
))
1257 if (wi::le_p (op2
.upper_bound (), wi::zero (prec
), sign
))
1260 // Always wrapping additions.
1261 else if (ovf1
&& ovf1
== ovf2
)
1263 // Positive op2 means lhs < op1.
1264 if (wi::gt_p (op2
.lower_bound (), wi::zero (prec
), sign
))
1266 if (wi::ge_p (op2
.lower_bound (), wi::zero (prec
), sign
))
1269 // Negative op2 means lhs > op1.
1270 if (wi::lt_p (op2
.upper_bound (), wi::zero (prec
), sign
))
1272 if (wi::le_p (op2
.upper_bound (), wi::zero (prec
), sign
))
1276 // If op2 does not contain 0, then LHS and OP1 can never be equal.
1277 if (!range_includes_zero_p (&op2
))
1280 return VREL_VARYING
;
1283 // PLUS is symmetrical, so we can simply call lhs_op1_relation with reversed
1287 operator_plus::lhs_op2_relation (const irange
&lhs
, const irange
&op1
,
1288 const irange
&op2
, relation_kind rel
) const
1290 return lhs_op1_relation (lhs
, op2
, op1
, rel
);
1294 operator_plus::wi_fold (irange
&r
, tree type
,
1295 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1296 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
1298 wi::overflow_type ov_lb
, ov_ub
;
1299 signop s
= TYPE_SIGN (type
);
1300 wide_int new_lb
= wi::add (lh_lb
, rh_lb
, s
, &ov_lb
);
1301 wide_int new_ub
= wi::add (lh_ub
, rh_ub
, s
, &ov_ub
);
1302 value_range_with_overflow (r
, type
, new_lb
, new_ub
, ov_lb
, ov_ub
);
1306 operator_plus::op1_range (irange
&r
, tree type
,
1309 relation_kind rel ATTRIBUTE_UNUSED
) const
1311 return range_op_handler (MINUS_EXPR
, type
).fold_range (r
, type
, lhs
, op2
);
1315 operator_plus::op2_range (irange
&r
, tree type
,
1318 relation_kind rel ATTRIBUTE_UNUSED
) const
1320 return range_op_handler (MINUS_EXPR
, type
).fold_range (r
, type
, lhs
, op1
);
1324 class operator_minus
: public range_operator
1326 using range_operator::fold_range
;
1327 using range_operator::op1_range
;
1328 using range_operator::op2_range
;
1330 virtual bool op1_range (irange
&r
, tree type
,
1333 relation_kind rel ATTRIBUTE_UNUSED
) const;
1334 virtual bool op2_range (irange
&r
, tree type
,
1337 relation_kind rel ATTRIBUTE_UNUSED
) const;
1338 virtual void wi_fold (irange
&r
, tree type
,
1339 const wide_int
&lh_lb
,
1340 const wide_int
&lh_ub
,
1341 const wide_int
&rh_lb
,
1342 const wide_int
&rh_ub
) const;
1343 virtual relation_kind
lhs_op1_relation (const irange
&lhs
,
1346 relation_kind rel
) const;
1347 virtual bool op1_op2_relation_effect (irange
&lhs_range
,
1349 const irange
&op1_range
,
1350 const irange
&op2_range
,
1351 relation_kind rel
) const;
1355 operator_minus::wi_fold (irange
&r
, tree type
,
1356 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1357 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
1359 wi::overflow_type ov_lb
, ov_ub
;
1360 signop s
= TYPE_SIGN (type
);
1361 wide_int new_lb
= wi::sub (lh_lb
, rh_ub
, s
, &ov_lb
);
1362 wide_int new_ub
= wi::sub (lh_ub
, rh_lb
, s
, &ov_ub
);
1363 value_range_with_overflow (r
, type
, new_lb
, new_ub
, ov_lb
, ov_ub
);
1367 // Return the relation between LHS and OP1 based on the relation between
1371 operator_minus::lhs_op1_relation (const irange
&, const irange
&op1
,
1372 const irange
&, relation_kind rel
) const
1374 if (!op1
.undefined_p () && TYPE_SIGN (op1
.type ()) == UNSIGNED
)
1384 return VREL_VARYING
;
1387 // Check to see if the relation REL between OP1 and OP2 has any effect on the
1388 // LHS of the expression. If so, apply it to LHS_RANGE. This is a helper
1389 // function for both MINUS_EXPR and POINTER_DIFF_EXPR.
1392 minus_op1_op2_relation_effect (irange
&lhs_range
, tree type
,
1393 const irange
&op1_range ATTRIBUTE_UNUSED
,
1394 const irange
&op2_range ATTRIBUTE_UNUSED
,
1397 if (rel
== VREL_VARYING
)
1400 int_range
<2> rel_range
;
1401 unsigned prec
= TYPE_PRECISION (type
);
1402 signop sgn
= TYPE_SIGN (type
);
1404 // == and != produce [0,0] and ~[0,0] regardless of wrapping.
1406 rel_range
= int_range
<2> (type
, wi::zero (prec
), wi::zero (prec
));
1407 else if (rel
== VREL_NE
)
1408 rel_range
= int_range
<2> (type
, wi::zero (prec
), wi::zero (prec
),
1410 else if (TYPE_OVERFLOW_WRAPS (type
))
1414 // For wrapping signed values and unsigned, if op1 > op2 or
1415 // op1 < op2, then op1 - op2 can be restricted to ~[0, 0].
1418 rel_range
= int_range
<2> (type
, wi::zero (prec
), wi::zero (prec
),
1429 // op1 > op2, op1 - op2 can be restricted to [1, +INF]
1431 rel_range
= int_range
<2> (type
, wi::one (prec
),
1432 wi::max_value (prec
, sgn
));
1434 // op1 >= op2, op1 - op2 can be restricted to [0, +INF]
1436 rel_range
= int_range
<2> (type
, wi::zero (prec
),
1437 wi::max_value (prec
, sgn
));
1439 // op1 < op2, op1 - op2 can be restricted to [-INF, -1]
1441 rel_range
= int_range
<2> (type
, wi::min_value (prec
, sgn
),
1442 wi::minus_one (prec
));
1444 // op1 <= op2, op1 - op2 can be restricted to [-INF, 0]
1446 rel_range
= int_range
<2> (type
, wi::min_value (prec
, sgn
),
1453 lhs_range
.intersect (rel_range
);
1458 operator_minus::op1_op2_relation_effect (irange
&lhs_range
, tree type
,
1459 const irange
&op1_range
,
1460 const irange
&op2_range
,
1461 relation_kind rel
) const
1463 return minus_op1_op2_relation_effect (lhs_range
, type
, op1_range
, op2_range
,
1468 operator_minus::op1_range (irange
&r
, tree type
,
1471 relation_kind rel ATTRIBUTE_UNUSED
) const
1473 return range_op_handler (PLUS_EXPR
, type
).fold_range (r
, type
, lhs
, op2
);
1477 operator_minus::op2_range (irange
&r
, tree type
,
1480 relation_kind rel ATTRIBUTE_UNUSED
) const
1482 return fold_range (r
, type
, op1
, lhs
);
1486 class operator_pointer_diff
: public range_operator
1488 virtual bool op1_op2_relation_effect (irange
&lhs_range
,
1490 const irange
&op1_range
,
1491 const irange
&op2_range
,
1492 relation_kind rel
) const;
1496 operator_pointer_diff::op1_op2_relation_effect (irange
&lhs_range
, tree type
,
1497 const irange
&op1_range
,
1498 const irange
&op2_range
,
1499 relation_kind rel
) const
1501 return minus_op1_op2_relation_effect (lhs_range
, type
, op1_range
, op2_range
,
1506 class operator_min
: public range_operator
1509 virtual void wi_fold (irange
&r
, tree type
,
1510 const wide_int
&lh_lb
,
1511 const wide_int
&lh_ub
,
1512 const wide_int
&rh_lb
,
1513 const wide_int
&rh_ub
) const;
1517 operator_min::wi_fold (irange
&r
, tree type
,
1518 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1519 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
1521 signop s
= TYPE_SIGN (type
);
1522 wide_int new_lb
= wi::min (lh_lb
, rh_lb
, s
);
1523 wide_int new_ub
= wi::min (lh_ub
, rh_ub
, s
);
1524 value_range_with_overflow (r
, type
, new_lb
, new_ub
);
1528 class operator_max
: public range_operator
1531 virtual void wi_fold (irange
&r
, tree type
,
1532 const wide_int
&lh_lb
,
1533 const wide_int
&lh_ub
,
1534 const wide_int
&rh_lb
,
1535 const wide_int
&rh_ub
) const;
1539 operator_max::wi_fold (irange
&r
, tree type
,
1540 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1541 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
1543 signop s
= TYPE_SIGN (type
);
1544 wide_int new_lb
= wi::max (lh_lb
, rh_lb
, s
);
1545 wide_int new_ub
= wi::max (lh_ub
, rh_ub
, s
);
1546 value_range_with_overflow (r
, type
, new_lb
, new_ub
);
1550 class cross_product_operator
: public range_operator
1553 // Perform an operation between two wide-ints and place the result
1554 // in R. Return true if the operation overflowed.
1555 virtual bool wi_op_overflows (wide_int
&r
,
1558 const wide_int
&) const = 0;
1560 // Calculate the cross product of two sets of sub-ranges and return it.
1561 void wi_cross_product (irange
&r
, tree type
,
1562 const wide_int
&lh_lb
,
1563 const wide_int
&lh_ub
,
1564 const wide_int
&rh_lb
,
1565 const wide_int
&rh_ub
) const;
1568 // Calculate the cross product of two sets of ranges and return it.
1570 // Multiplications, divisions and shifts are a bit tricky to handle,
1571 // depending on the mix of signs we have in the two ranges, we need to
1572 // operate on different values to get the minimum and maximum values
1573 // for the new range. One approach is to figure out all the
1574 // variations of range combinations and do the operations.
1576 // However, this involves several calls to compare_values and it is
1577 // pretty convoluted. It's simpler to do the 4 operations (MIN0 OP
1578 // MIN1, MIN0 OP MAX1, MAX0 OP MIN1 and MAX0 OP MAX0 OP MAX1) and then
1579 // figure the smallest and largest values to form the new range.
1582 cross_product_operator::wi_cross_product (irange
&r
, tree type
,
1583 const wide_int
&lh_lb
,
1584 const wide_int
&lh_ub
,
1585 const wide_int
&rh_lb
,
1586 const wide_int
&rh_ub
) const
1588 wide_int cp1
, cp2
, cp3
, cp4
;
1589 // Default to varying.
1590 r
.set_varying (type
);
1592 // Compute the 4 cross operations, bailing if we get an overflow we
1594 if (wi_op_overflows (cp1
, type
, lh_lb
, rh_lb
))
1596 if (wi::eq_p (lh_lb
, lh_ub
))
1598 else if (wi_op_overflows (cp3
, type
, lh_ub
, rh_lb
))
1600 if (wi::eq_p (rh_lb
, rh_ub
))
1602 else if (wi_op_overflows (cp2
, type
, lh_lb
, rh_ub
))
1604 if (wi::eq_p (lh_lb
, lh_ub
))
1606 else if (wi_op_overflows (cp4
, type
, lh_ub
, rh_ub
))
1610 signop sign
= TYPE_SIGN (type
);
1611 if (wi::gt_p (cp1
, cp2
, sign
))
1612 std::swap (cp1
, cp2
);
1613 if (wi::gt_p (cp3
, cp4
, sign
))
1614 std::swap (cp3
, cp4
);
1616 // Choose min and max from the ordered pairs.
1617 wide_int res_lb
= wi::min (cp1
, cp3
, sign
);
1618 wide_int res_ub
= wi::max (cp2
, cp4
, sign
);
1619 value_range_with_overflow (r
, type
, res_lb
, res_ub
);
1623 class operator_mult
: public cross_product_operator
1625 using range_operator::op1_range
;
1626 using range_operator::op2_range
;
1628 virtual void wi_fold (irange
&r
, tree type
,
1629 const wide_int
&lh_lb
,
1630 const wide_int
&lh_ub
,
1631 const wide_int
&rh_lb
,
1632 const wide_int
&rh_ub
) const;
1633 virtual bool wi_op_overflows (wide_int
&res
, tree type
,
1634 const wide_int
&w0
, const wide_int
&w1
) const;
1635 virtual bool op1_range (irange
&r
, tree type
,
1638 relation_kind rel ATTRIBUTE_UNUSED
) const;
1639 virtual bool op2_range (irange
&r
, tree type
,
1642 relation_kind rel ATTRIBUTE_UNUSED
) const;
1646 operator_mult::op1_range (irange
&r
, tree type
,
1647 const irange
&lhs
, const irange
&op2
,
1648 relation_kind rel ATTRIBUTE_UNUSED
) const
1652 // We can't solve 0 = OP1 * N by dividing by N with a wrapping type.
1653 // For example: For 0 = OP1 * 2, OP1 could be 0, or MAXINT, whereas
1654 // for 4 = OP1 * 2, OP1 could be 2 or 130 (unsigned 8-bit)
1655 if (TYPE_OVERFLOW_WRAPS (type
))
1658 if (op2
.singleton_p (&offset
) && !integer_zerop (offset
))
1659 return range_op_handler (TRUNC_DIV_EXPR
, type
).fold_range (r
, type
,
1665 operator_mult::op2_range (irange
&r
, tree type
,
1666 const irange
&lhs
, const irange
&op1
,
1667 relation_kind rel
) const
1669 return operator_mult::op1_range (r
, type
, lhs
, op1
, rel
);
1673 operator_mult::wi_op_overflows (wide_int
&res
, tree type
,
1674 const wide_int
&w0
, const wide_int
&w1
) const
1676 wi::overflow_type overflow
= wi::OVF_NONE
;
1677 signop sign
= TYPE_SIGN (type
);
1678 res
= wi::mul (w0
, w1
, sign
, &overflow
);
1679 if (overflow
&& TYPE_OVERFLOW_UNDEFINED (type
))
1681 // For multiplication, the sign of the overflow is given
1682 // by the comparison of the signs of the operands.
1683 if (sign
== UNSIGNED
|| w0
.sign_mask () == w1
.sign_mask ())
1684 res
= wi::max_value (w0
.get_precision (), sign
);
1686 res
= wi::min_value (w0
.get_precision (), sign
);
1693 operator_mult::wi_fold (irange
&r
, tree type
,
1694 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1695 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
1697 if (TYPE_OVERFLOW_UNDEFINED (type
))
1699 wi_cross_product (r
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
);
1703 // Multiply the ranges when overflow wraps. This is basically fancy
1704 // code so we don't drop to varying with an unsigned
1707 // This test requires 2*prec bits if both operands are signed and
1708 // 2*prec + 2 bits if either is not. Therefore, extend the values
1709 // using the sign of the result to PREC2. From here on out,
1710 // everthing is just signed math no matter what the input types
1713 signop sign
= TYPE_SIGN (type
);
1714 unsigned prec
= TYPE_PRECISION (type
);
1715 widest2_int min0
= widest2_int::from (lh_lb
, sign
);
1716 widest2_int max0
= widest2_int::from (lh_ub
, sign
);
1717 widest2_int min1
= widest2_int::from (rh_lb
, sign
);
1718 widest2_int max1
= widest2_int::from (rh_ub
, sign
);
1719 widest2_int sizem1
= wi::mask
<widest2_int
> (prec
, false);
1720 widest2_int size
= sizem1
+ 1;
1722 // Canonicalize the intervals.
1723 if (sign
== UNSIGNED
)
1725 if (wi::ltu_p (size
, min0
+ max0
))
1730 if (wi::ltu_p (size
, min1
+ max1
))
1737 // Sort the 4 products so that min is in prod0 and max is in
1739 widest2_int prod0
= min0
* min1
;
1740 widest2_int prod1
= min0
* max1
;
1741 widest2_int prod2
= max0
* min1
;
1742 widest2_int prod3
= max0
* max1
;
1744 // min0min1 > max0max1
1746 std::swap (prod0
, prod3
);
1748 // min0max1 > max0min1
1750 std::swap (prod1
, prod2
);
1753 std::swap (prod0
, prod1
);
1756 std::swap (prod2
, prod3
);
1759 prod2
= prod3
- prod0
;
1760 if (wi::geu_p (prod2
, sizem1
))
1761 // The range covers all values.
1762 r
.set_varying (type
);
1765 wide_int new_lb
= wide_int::from (prod0
, prec
, sign
);
1766 wide_int new_ub
= wide_int::from (prod3
, prec
, sign
);
1767 create_possibly_reversed_range (r
, type
, new_lb
, new_ub
);
1772 class operator_div
: public cross_product_operator
1775 operator_div (enum tree_code c
) { code
= c
; }
1776 virtual void wi_fold (irange
&r
, tree type
,
1777 const wide_int
&lh_lb
,
1778 const wide_int
&lh_ub
,
1779 const wide_int
&rh_lb
,
1780 const wide_int
&rh_ub
) const;
1781 virtual bool wi_op_overflows (wide_int
&res
, tree type
,
1782 const wide_int
&, const wide_int
&) const;
1784 enum tree_code code
;
1788 operator_div::wi_op_overflows (wide_int
&res
, tree type
,
1789 const wide_int
&w0
, const wide_int
&w1
) const
1794 wi::overflow_type overflow
= wi::OVF_NONE
;
1795 signop sign
= TYPE_SIGN (type
);
1799 case EXACT_DIV_EXPR
:
1800 // EXACT_DIV_EXPR is implemented as TRUNC_DIV_EXPR in
1801 // operator_exact_divide. No need to handle it here.
1804 case TRUNC_DIV_EXPR
:
1805 res
= wi::div_trunc (w0
, w1
, sign
, &overflow
);
1807 case FLOOR_DIV_EXPR
:
1808 res
= wi::div_floor (w0
, w1
, sign
, &overflow
);
1810 case ROUND_DIV_EXPR
:
1811 res
= wi::div_round (w0
, w1
, sign
, &overflow
);
1814 res
= wi::div_ceil (w0
, w1
, sign
, &overflow
);
1820 if (overflow
&& TYPE_OVERFLOW_UNDEFINED (type
))
1822 // For division, the only case is -INF / -1 = +INF.
1823 res
= wi::max_value (w0
.get_precision (), sign
);
1830 operator_div::wi_fold (irange
&r
, tree type
,
1831 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1832 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
1834 const wide_int dividend_min
= lh_lb
;
1835 const wide_int dividend_max
= lh_ub
;
1836 const wide_int divisor_min
= rh_lb
;
1837 const wide_int divisor_max
= rh_ub
;
1838 signop sign
= TYPE_SIGN (type
);
1839 unsigned prec
= TYPE_PRECISION (type
);
1840 wide_int extra_min
, extra_max
;
1842 // If we know we won't divide by zero, just do the division.
1843 if (!wi_includes_zero_p (type
, divisor_min
, divisor_max
))
1845 wi_cross_product (r
, type
, dividend_min
, dividend_max
,
1846 divisor_min
, divisor_max
);
1850 // If we're definitely dividing by zero, there's nothing to do.
1851 if (wi_zero_p (type
, divisor_min
, divisor_max
))
1857 // Perform the division in 2 parts, [LB, -1] and [1, UB], which will
1858 // skip any division by zero.
1860 // First divide by the negative numbers, if any.
1861 if (wi::neg_p (divisor_min
, sign
))
1862 wi_cross_product (r
, type
, dividend_min
, dividend_max
,
1863 divisor_min
, wi::minus_one (prec
));
1867 // Then divide by the non-zero positive numbers, if any.
1868 if (wi::gt_p (divisor_max
, wi::zero (prec
), sign
))
1871 wi_cross_product (tmp
, type
, dividend_min
, dividend_max
,
1872 wi::one (prec
), divisor_max
);
1875 // We shouldn't still have undefined here.
1876 gcc_checking_assert (!r
.undefined_p ());
1879 operator_div
op_trunc_div (TRUNC_DIV_EXPR
);
1880 operator_div
op_floor_div (FLOOR_DIV_EXPR
);
1881 operator_div
op_round_div (ROUND_DIV_EXPR
);
1882 operator_div
op_ceil_div (CEIL_DIV_EXPR
);
1885 class operator_exact_divide
: public operator_div
1887 using range_operator::op1_range
;
1889 operator_exact_divide () : operator_div (TRUNC_DIV_EXPR
) { }
1890 virtual bool op1_range (irange
&r
, tree type
,
1893 relation_kind rel ATTRIBUTE_UNUSED
) const;
1898 operator_exact_divide::op1_range (irange
&r
, tree type
,
1901 relation_kind rel ATTRIBUTE_UNUSED
) const
1904 // [2, 4] = op1 / [3,3] since its exact divide, no need to worry about
1905 // remainders in the endpoints, so op1 = [2,4] * [3,3] = [6,12].
1906 // We wont bother trying to enumerate all the in between stuff :-P
1907 // TRUE accuraacy is [6,6][9,9][12,12]. This is unlikely to matter most of
1908 // the time however.
1909 // If op2 is a multiple of 2, we would be able to set some non-zero bits.
1910 if (op2
.singleton_p (&offset
)
1911 && !integer_zerop (offset
))
1912 return range_op_handler (MULT_EXPR
, type
).fold_range (r
, type
, lhs
, op2
);
1917 class operator_lshift
: public cross_product_operator
1919 using range_operator::fold_range
;
1920 using range_operator::op1_range
;
1922 virtual bool op1_range (irange
&r
, tree type
,
1925 relation_kind rel
= VREL_VARYING
) const;
1926 virtual bool fold_range (irange
&r
, tree type
,
1929 relation_kind rel
= VREL_VARYING
) const;
1931 virtual void wi_fold (irange
&r
, tree type
,
1932 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
1933 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const;
1934 virtual bool wi_op_overflows (wide_int
&res
,
1937 const wide_int
&) const;
1940 class operator_rshift
: public cross_product_operator
1942 using range_operator::fold_range
;
1943 using range_operator::op1_range
;
1944 using range_operator::lhs_op1_relation
;
1946 virtual bool fold_range (irange
&r
, tree type
,
1949 relation_kind rel
= VREL_VARYING
) const;
1950 virtual void wi_fold (irange
&r
, tree type
,
1951 const wide_int
&lh_lb
,
1952 const wide_int
&lh_ub
,
1953 const wide_int
&rh_lb
,
1954 const wide_int
&rh_ub
) const;
1955 virtual bool wi_op_overflows (wide_int
&res
,
1958 const wide_int
&w1
) const;
1959 virtual bool op1_range (irange
&, tree type
,
1962 relation_kind rel
= VREL_VARYING
) const;
1963 virtual relation_kind
lhs_op1_relation (const irange
&lhs
,
1966 relation_kind rel
) const;
1971 operator_rshift::lhs_op1_relation (const irange
&lhs ATTRIBUTE_UNUSED
,
1974 relation_kind
) const
1976 // If both operands range are >= 0, then the LHS <= op1.
1977 if (!op1
.undefined_p () && !op2
.undefined_p ()
1978 && wi::ge_p (op1
.lower_bound (), 0, TYPE_SIGN (op1
.type ()))
1979 && wi::ge_p (op2
.lower_bound (), 0, TYPE_SIGN (op2
.type ())))
1981 return VREL_VARYING
;
1985 operator_lshift::fold_range (irange
&r
, tree type
,
1988 relation_kind rel
) const
1990 int_range_max shift_range
;
1991 if (!get_shift_range (shift_range
, type
, op2
))
1993 if (op2
.undefined_p ())
1996 r
.set_varying (type
);
2000 // Transform left shifts by constants into multiplies.
2001 if (shift_range
.singleton_p ())
2003 unsigned shift
= shift_range
.lower_bound ().to_uhwi ();
2004 wide_int tmp
= wi::set_bit_in_zero (shift
, TYPE_PRECISION (type
));
2005 int_range
<1> mult (type
, tmp
, tmp
);
2007 // Force wrapping multiplication.
2008 bool saved_flag_wrapv
= flag_wrapv
;
2009 bool saved_flag_wrapv_pointer
= flag_wrapv_pointer
;
2011 flag_wrapv_pointer
= 1;
2012 bool b
= op_mult
.fold_range (r
, type
, op1
, mult
);
2013 flag_wrapv
= saved_flag_wrapv
;
2014 flag_wrapv_pointer
= saved_flag_wrapv_pointer
;
2018 // Otherwise, invoke the generic fold routine.
2019 return range_operator::fold_range (r
, type
, op1
, shift_range
, rel
);
2023 operator_lshift::wi_fold (irange
&r
, tree type
,
2024 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
2025 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
2027 signop sign
= TYPE_SIGN (type
);
2028 unsigned prec
= TYPE_PRECISION (type
);
2029 int overflow_pos
= sign
== SIGNED
? prec
- 1 : prec
;
2030 int bound_shift
= overflow_pos
- rh_ub
.to_shwi ();
2031 // If bound_shift == HOST_BITS_PER_WIDE_INT, the llshift can
2032 // overflow. However, for that to happen, rh.max needs to be zero,
2033 // which means rh is a singleton range of zero, which means we simply return
2034 // [lh_lb, lh_ub] as the range.
2035 if (wi::eq_p (rh_ub
, rh_lb
) && wi::eq_p (rh_ub
, 0))
2037 r
= int_range
<2> (type
, lh_lb
, lh_ub
);
2041 wide_int bound
= wi::set_bit_in_zero (bound_shift
, prec
);
2042 wide_int complement
= ~(bound
- 1);
2043 wide_int low_bound
, high_bound
;
2044 bool in_bounds
= false;
2046 if (sign
== UNSIGNED
)
2049 high_bound
= complement
;
2050 if (wi::ltu_p (lh_ub
, low_bound
))
2052 // [5, 6] << [1, 2] == [10, 24].
2053 // We're shifting out only zeroes, the value increases
2057 else if (wi::ltu_p (high_bound
, lh_lb
))
2059 // [0xffffff00, 0xffffffff] << [1, 2]
2060 // == [0xfffffc00, 0xfffffffe].
2061 // We're shifting out only ones, the value decreases
2068 // [-1, 1] << [1, 2] == [-4, 4]
2069 low_bound
= complement
;
2071 if (wi::lts_p (lh_ub
, high_bound
)
2072 && wi::lts_p (low_bound
, lh_lb
))
2074 // For non-negative numbers, we're shifting out only zeroes,
2075 // the value increases monotonically. For negative numbers,
2076 // we're shifting out only ones, the value decreases
2083 wi_cross_product (r
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
);
2085 r
.set_varying (type
);
2089 operator_lshift::wi_op_overflows (wide_int
&res
, tree type
,
2090 const wide_int
&w0
, const wide_int
&w1
) const
2092 signop sign
= TYPE_SIGN (type
);
2095 // It's unclear from the C standard whether shifts can overflow.
2096 // The following code ignores overflow; perhaps a C standard
2097 // interpretation ruling is needed.
2098 res
= wi::rshift (w0
, -w1
, sign
);
2101 res
= wi::lshift (w0
, w1
);
2106 operator_lshift::op1_range (irange
&r
,
2110 relation_kind rel ATTRIBUTE_UNUSED
) const
2114 if (!lhs
.contains_p (build_zero_cst (type
)))
2115 r
.set_nonzero (type
);
2117 r
.set_varying (type
);
2119 if (op2
.singleton_p (&shift_amount
))
2121 wide_int shift
= wi::to_wide (shift_amount
);
2122 if (wi::lt_p (shift
, 0, SIGNED
))
2124 if (wi::ge_p (shift
, wi::uhwi (TYPE_PRECISION (type
),
2125 TYPE_PRECISION (op2
.type ())),
2134 // Work completely in unsigned mode to start.
2136 int_range_max tmp_range
;
2137 if (TYPE_SIGN (type
) == SIGNED
)
2139 int_range_max tmp
= lhs
;
2140 utype
= unsigned_type_for (type
);
2141 range_cast (tmp
, utype
);
2142 op_rshift
.fold_range (tmp_range
, utype
, tmp
, op2
);
2145 op_rshift
.fold_range (tmp_range
, utype
, lhs
, op2
);
2147 // Start with ranges which can produce the LHS by right shifting the
2148 // result by the shift amount.
2149 // ie [0x08, 0xF0] = op1 << 2 will start with
2150 // [00001000, 11110000] = op1 << 2
2151 // [0x02, 0x4C] aka [00000010, 00111100]
2153 // Then create a range from the LB with the least significant upper bit
2154 // set, to the upper bound with all the bits set.
2155 // This would be [0x42, 0xFC] aka [01000010, 11111100].
2157 // Ideally we do this for each subrange, but just lump them all for now.
2158 unsigned low_bits
= TYPE_PRECISION (utype
)
2159 - TREE_INT_CST_LOW (shift_amount
);
2160 wide_int up_mask
= wi::mask (low_bits
, true, TYPE_PRECISION (utype
));
2161 wide_int new_ub
= wi::bit_or (up_mask
, tmp_range
.upper_bound ());
2162 wide_int new_lb
= wi::set_bit (tmp_range
.lower_bound (), low_bits
);
2163 int_range
<2> fill_range (utype
, new_lb
, new_ub
);
2164 tmp_range
.union_ (fill_range
);
2167 range_cast (tmp_range
, type
);
2169 r
.intersect (tmp_range
);
2173 return !r
.varying_p ();
2177 operator_rshift::op1_range (irange
&r
,
2181 relation_kind rel ATTRIBUTE_UNUSED
) const
2184 if (op2
.singleton_p (&shift
))
2186 // Ignore nonsensical shifts.
2187 unsigned prec
= TYPE_PRECISION (type
);
2188 if (wi::ge_p (wi::to_wide (shift
),
2189 wi::uhwi (prec
, TYPE_PRECISION (TREE_TYPE (shift
))),
2192 if (wi::to_wide (shift
) == 0)
2198 // Folding the original operation may discard some impossible
2199 // ranges from the LHS.
2200 int_range_max lhs_refined
;
2201 op_rshift
.fold_range (lhs_refined
, type
, int_range
<1> (type
), op2
);
2202 lhs_refined
.intersect (lhs
);
2203 if (lhs_refined
.undefined_p ())
2208 int_range_max
shift_range (shift
, shift
);
2209 int_range_max lb
, ub
;
2210 op_lshift
.fold_range (lb
, type
, lhs_refined
, shift_range
);
2212 // 0000 0111 = OP1 >> 3
2214 // OP1 is anything from 0011 1000 to 0011 1111. That is, a
2215 // range from LHS<<3 plus a mask of the 3 bits we shifted on the
2216 // right hand side (0x07).
2217 tree mask
= fold_build1 (BIT_NOT_EXPR
, type
,
2218 fold_build2 (LSHIFT_EXPR
, type
,
2219 build_minus_one_cst (type
),
2221 int_range_max
mask_range (build_zero_cst (type
), mask
);
2222 op_plus
.fold_range (ub
, type
, lb
, mask_range
);
2225 if (!lhs_refined
.contains_p (build_zero_cst (type
)))
2227 mask_range
.invert ();
2228 r
.intersect (mask_range
);
2236 operator_rshift::wi_op_overflows (wide_int
&res
,
2239 const wide_int
&w1
) const
2241 signop sign
= TYPE_SIGN (type
);
2243 res
= wi::lshift (w0
, -w1
);
2246 // It's unclear from the C standard whether shifts can overflow.
2247 // The following code ignores overflow; perhaps a C standard
2248 // interpretation ruling is needed.
2249 res
= wi::rshift (w0
, w1
, sign
);
2255 operator_rshift::fold_range (irange
&r
, tree type
,
2258 relation_kind rel
) const
2260 int_range_max shift
;
2261 if (!get_shift_range (shift
, type
, op2
))
2263 if (op2
.undefined_p ())
2266 r
.set_varying (type
);
2270 return range_operator::fold_range (r
, type
, op1
, shift
, rel
);
2274 operator_rshift::wi_fold (irange
&r
, tree type
,
2275 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
2276 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const
2278 wi_cross_product (r
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
);
2282 class operator_cast
: public range_operator
2284 using range_operator::fold_range
;
2285 using range_operator::op1_range
;
2287 virtual bool fold_range (irange
&r
, tree type
,
2290 relation_kind rel
= VREL_VARYING
) const;
2291 virtual bool op1_range (irange
&r
, tree type
,
2294 relation_kind rel
= VREL_VARYING
) const;
2296 bool truncating_cast_p (const irange
&inner
, const irange
&outer
) const;
2297 bool inside_domain_p (const wide_int
&min
, const wide_int
&max
,
2298 const irange
&outer
) const;
2299 void fold_pair (irange
&r
, unsigned index
, const irange
&inner
,
2300 const irange
&outer
) const;
2303 // Return TRUE if casting from INNER to OUTER is a truncating cast.
2306 operator_cast::truncating_cast_p (const irange
&inner
,
2307 const irange
&outer
) const
2309 return TYPE_PRECISION (outer
.type ()) < TYPE_PRECISION (inner
.type ());
2312 // Return TRUE if [MIN,MAX] is inside the domain of RANGE's type.
2315 operator_cast::inside_domain_p (const wide_int
&min
,
2316 const wide_int
&max
,
2317 const irange
&range
) const
2319 wide_int domain_min
= wi::to_wide (vrp_val_min (range
.type ()));
2320 wide_int domain_max
= wi::to_wide (vrp_val_max (range
.type ()));
2321 signop domain_sign
= TYPE_SIGN (range
.type ());
2322 return (wi::le_p (min
, domain_max
, domain_sign
)
2323 && wi::le_p (max
, domain_max
, domain_sign
)
2324 && wi::ge_p (min
, domain_min
, domain_sign
)
2325 && wi::ge_p (max
, domain_min
, domain_sign
));
2329 // Helper for fold_range which work on a pair at a time.
2332 operator_cast::fold_pair (irange
&r
, unsigned index
,
2333 const irange
&inner
,
2334 const irange
&outer
) const
2336 tree inner_type
= inner
.type ();
2337 tree outer_type
= outer
.type ();
2338 signop inner_sign
= TYPE_SIGN (inner_type
);
2339 unsigned outer_prec
= TYPE_PRECISION (outer_type
);
2341 // check to see if casting from INNER to OUTER is a conversion that
2342 // fits in the resulting OUTER type.
2343 wide_int inner_lb
= inner
.lower_bound (index
);
2344 wide_int inner_ub
= inner
.upper_bound (index
);
2345 if (truncating_cast_p (inner
, outer
))
2347 // We may be able to accomodate a truncating cast if the
2348 // resulting range can be represented in the target type...
2349 if (wi::rshift (wi::sub (inner_ub
, inner_lb
),
2350 wi::uhwi (outer_prec
, TYPE_PRECISION (inner
.type ())),
2353 r
.set_varying (outer_type
);
2357 // ...but we must still verify that the final range fits in the
2358 // domain. This catches -fstrict-enum restrictions where the domain
2359 // range is smaller than what fits in the underlying type.
2360 wide_int min
= wide_int::from (inner_lb
, outer_prec
, inner_sign
);
2361 wide_int max
= wide_int::from (inner_ub
, outer_prec
, inner_sign
);
2362 if (inside_domain_p (min
, max
, outer
))
2363 create_possibly_reversed_range (r
, outer_type
, min
, max
);
2365 r
.set_varying (outer_type
);
2370 operator_cast::fold_range (irange
&r
, tree type ATTRIBUTE_UNUSED
,
2371 const irange
&inner
,
2372 const irange
&outer
,
2373 relation_kind rel ATTRIBUTE_UNUSED
) const
2375 if (empty_range_varying (r
, type
, inner
, outer
))
2378 gcc_checking_assert (outer
.varying_p ());
2379 gcc_checking_assert (inner
.num_pairs () > 0);
2381 // Avoid a temporary by folding the first pair directly into the result.
2382 fold_pair (r
, 0, inner
, outer
);
2384 // Then process any additonal pairs by unioning with their results.
2385 for (unsigned x
= 1; x
< inner
.num_pairs (); ++x
)
2388 fold_pair (tmp
, x
, inner
, outer
);
2397 operator_cast::op1_range (irange
&r
, tree type
,
2400 relation_kind rel ATTRIBUTE_UNUSED
) const
2402 tree lhs_type
= lhs
.type ();
2403 gcc_checking_assert (types_compatible_p (op2
.type(), type
));
2405 // If we are calculating a pointer, shortcut to what we really care about.
2406 if (POINTER_TYPE_P (type
))
2408 // Conversion from other pointers or a constant (including 0/NULL)
2409 // are straightforward.
2410 if (POINTER_TYPE_P (lhs
.type ())
2411 || (lhs
.singleton_p ()
2412 && TYPE_PRECISION (lhs
.type ()) >= TYPE_PRECISION (type
)))
2415 range_cast (r
, type
);
2419 // If the LHS is not a pointer nor a singleton, then it is
2420 // either VARYING or non-zero.
2421 if (!lhs
.contains_p (build_zero_cst (lhs
.type ())))
2422 r
.set_nonzero (type
);
2424 r
.set_varying (type
);
2430 if (truncating_cast_p (op2
, lhs
))
2432 if (lhs
.varying_p ())
2433 r
.set_varying (type
);
2436 // We want to insert the LHS as an unsigned value since it
2437 // would not trigger the signed bit of the larger type.
2438 int_range_max converted_lhs
= lhs
;
2439 range_cast (converted_lhs
, unsigned_type_for (lhs_type
));
2440 range_cast (converted_lhs
, type
);
2441 // Start by building the positive signed outer range for the type.
2442 wide_int lim
= wi::set_bit_in_zero (TYPE_PRECISION (lhs_type
),
2443 TYPE_PRECISION (type
));
2444 r
= int_range
<1> (type
, lim
, wi::max_value (TYPE_PRECISION (type
),
2446 // For the signed part, we need to simply union the 2 ranges now.
2447 r
.union_ (converted_lhs
);
2449 // Create maximal negative number outside of LHS bits.
2450 lim
= wi::mask (TYPE_PRECISION (lhs_type
), true,
2451 TYPE_PRECISION (type
));
2452 // Add this to the unsigned LHS range(s).
2453 int_range_max
lim_range (type
, lim
, lim
);
2454 int_range_max lhs_neg
;
2455 range_op_handler (PLUS_EXPR
, type
).fold_range (lhs_neg
, type
,
2458 // lhs_neg now has all the negative versions of the LHS.
2459 // Now union in all the values from SIGNED MIN (0x80000) to
2460 // lim-1 in order to fill in all the ranges with the upper
2463 // PR 97317. If the lhs has only 1 bit less precision than the rhs,
2464 // we don't need to create a range from min to lim-1
2465 // calculate neg range traps trying to create [lim, lim - 1].
2466 wide_int min_val
= wi::min_value (TYPE_PRECISION (type
), SIGNED
);
2469 int_range_max
neg (type
,
2470 wi::min_value (TYPE_PRECISION (type
),
2473 lhs_neg
.union_ (neg
);
2475 // And finally, munge the signed and unsigned portions.
2478 // And intersect with any known value passed in the extra operand.
2484 if (TYPE_PRECISION (lhs_type
) == TYPE_PRECISION (type
))
2488 // The cast is not truncating, and the range is restricted to
2489 // the range of the RHS by this assignment.
2491 // Cast the range of the RHS to the type of the LHS.
2492 fold_range (tmp
, lhs_type
, int_range
<1> (type
), int_range
<1> (lhs_type
));
2493 // Intersect this with the LHS range will produce the range,
2494 // which will be cast to the RHS type before returning.
2495 tmp
.intersect (lhs
);
2498 // Cast the calculated range to the type of the RHS.
2499 fold_range (r
, type
, tmp
, int_range
<1> (type
));
2504 class operator_logical_and
: public range_operator
2506 using range_operator::fold_range
;
2507 using range_operator::op1_range
;
2508 using range_operator::op2_range
;
2510 virtual bool fold_range (irange
&r
, tree type
,
2513 relation_kind rel
= VREL_VARYING
) const;
2514 virtual bool op1_range (irange
&r
, tree type
,
2517 relation_kind rel
= VREL_VARYING
) const;
2518 virtual bool op2_range (irange
&r
, tree type
,
2521 relation_kind rel
= VREL_VARYING
) const;
2526 operator_logical_and::fold_range (irange
&r
, tree type
,
2529 relation_kind rel ATTRIBUTE_UNUSED
) const
2531 if (empty_range_varying (r
, type
, lh
, rh
))
2534 // 0 && anything is 0.
2535 if ((wi::eq_p (lh
.lower_bound (), 0) && wi::eq_p (lh
.upper_bound (), 0))
2536 || (wi::eq_p (lh
.lower_bound (), 0) && wi::eq_p (rh
.upper_bound (), 0)))
2537 r
= range_false (type
);
2538 else if (lh
.contains_p (build_zero_cst (lh
.type ()))
2539 || rh
.contains_p (build_zero_cst (rh
.type ())))
2540 // To reach this point, there must be a logical 1 on each side, and
2541 // the only remaining question is whether there is a zero or not.
2542 r
= range_true_and_false (type
);
2544 r
= range_true (type
);
2549 operator_logical_and::op1_range (irange
&r
, tree type
,
2551 const irange
&op2 ATTRIBUTE_UNUSED
,
2552 relation_kind rel ATTRIBUTE_UNUSED
) const
2554 switch (get_bool_state (r
, lhs
, type
))
2557 // A true result means both sides of the AND must be true.
2558 r
= range_true (type
);
2561 // Any other result means only one side has to be false, the
2562 // other side can be anything. So we cannot be sure of any
2564 r
= range_true_and_false (type
);
2571 operator_logical_and::op2_range (irange
&r
, tree type
,
2574 relation_kind rel ATTRIBUTE_UNUSED
) const
2576 return operator_logical_and::op1_range (r
, type
, lhs
, op1
);
2580 class operator_bitwise_and
: public range_operator
2582 using range_operator::fold_range
;
2583 using range_operator::op1_range
;
2584 using range_operator::op2_range
;
2586 virtual bool fold_range (irange
&r
, tree type
,
2589 relation_kind rel
= VREL_VARYING
) const;
2590 virtual bool op1_range (irange
&r
, tree type
,
2593 relation_kind rel
= VREL_VARYING
) const;
2594 virtual bool op2_range (irange
&r
, tree type
,
2597 relation_kind rel
= VREL_VARYING
) const;
2598 virtual void wi_fold (irange
&r
, tree type
,
2599 const wide_int
&lh_lb
,
2600 const wide_int
&lh_ub
,
2601 const wide_int
&rh_lb
,
2602 const wide_int
&rh_ub
) const;
2604 void simple_op1_range_solver (irange
&r
, tree type
,
2606 const irange
&op2
) const;
2607 void remove_impossible_ranges (irange
&r
, const irange
&rh
) const;
2611 unsigned_singleton_p (const irange
&op
)
2614 if (op
.singleton_p (&mask
))
2616 wide_int x
= wi::to_wide (mask
);
2617 return wi::ge_p (x
, 0, TYPE_SIGN (op
.type ()));
2622 // Remove any ranges from R that are known to be impossible when an
2623 // range is ANDed with MASK.
2626 operator_bitwise_and::remove_impossible_ranges (irange
&r
,
2627 const irange
&rmask
) const
2629 if (r
.undefined_p () || !unsigned_singleton_p (rmask
))
2632 wide_int mask
= rmask
.lower_bound ();
2633 tree type
= r
.type ();
2634 int prec
= TYPE_PRECISION (type
);
2635 int leading_zeros
= wi::clz (mask
);
2636 int_range_max impossible_ranges
;
2638 /* We know that starting at the most significant bit, any 0 in the
2639 mask means the resulting range cannot contain a 1 in that same
2640 position. This means the following ranges are impossible:
2644 01xx xxxx [0100 0000, 0111 1111]
2645 001x xxxx [0010 0000, 0011 1111]
2646 0000 01xx [0000 0100, 0000 0111]
2647 0000 0001 [0000 0001, 0000 0001]
2649 wide_int one
= wi::one (prec
);
2650 for (int i
= 0; i
< prec
- leading_zeros
- 1; ++i
)
2651 if (wi::bit_and (mask
, wi::lshift (one
, wi::uhwi (i
, prec
))) == 0)
2653 tree lb
= fold_build2 (LSHIFT_EXPR
, type
,
2654 build_one_cst (type
),
2655 build_int_cst (type
, i
));
2656 tree ub_left
= fold_build1 (BIT_NOT_EXPR
, type
,
2657 fold_build2 (LSHIFT_EXPR
, type
,
2658 build_minus_one_cst (type
),
2659 build_int_cst (type
, i
)));
2660 tree ub_right
= fold_build2 (LSHIFT_EXPR
, type
,
2661 build_one_cst (type
),
2662 build_int_cst (type
, i
));
2663 tree ub
= fold_build2 (BIT_IOR_EXPR
, type
, ub_left
, ub_right
);
2664 impossible_ranges
.union_ (int_range
<1> (lb
, ub
));
2666 if (!impossible_ranges
.undefined_p ())
2668 impossible_ranges
.invert ();
2669 r
.intersect (impossible_ranges
);
2674 operator_bitwise_and::fold_range (irange
&r
, tree type
,
2677 relation_kind rel ATTRIBUTE_UNUSED
) const
2679 if (range_operator::fold_range (r
, type
, lh
, rh
))
2681 // FIXME: This is temporarily disabled because, though it
2682 // generates better ranges, it's noticeably slower for evrp.
2683 // remove_impossible_ranges (r, rh);
2690 // Optimize BIT_AND_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR of signed types
2691 // by considering the number of leading redundant sign bit copies.
2692 // clrsb (X op Y) = min (clrsb (X), clrsb (Y)), so for example
2693 // [-1, 0] op [-1, 0] is [-1, 0] (where nonzero_bits doesn't help).
2695 wi_optimize_signed_bitwise_op (irange
&r
, tree type
,
2696 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
2697 const wide_int
&rh_lb
, const wide_int
&rh_ub
)
2699 int lh_clrsb
= MIN (wi::clrsb (lh_lb
), wi::clrsb (lh_ub
));
2700 int rh_clrsb
= MIN (wi::clrsb (rh_lb
), wi::clrsb (rh_ub
));
2701 int new_clrsb
= MIN (lh_clrsb
, rh_clrsb
);
2704 int type_prec
= TYPE_PRECISION (type
);
2705 int rprec
= (type_prec
- new_clrsb
) - 1;
2706 value_range_with_overflow (r
, type
,
2707 wi::mask (rprec
, true, type_prec
),
2708 wi::mask (rprec
, false, type_prec
));
2713 // Optimize BIT_AND_EXPR and BIT_IOR_EXPR in terms of a mask if
2714 // possible. Basically, see if we can optimize:
2718 // [LB op Z, UB op Z]
2720 // If the optimization was successful, accumulate the range in R and
2724 wi_optimize_and_or (irange
&r
,
2725 enum tree_code code
,
2727 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
2728 const wide_int
&rh_lb
, const wide_int
&rh_ub
)
2730 // Calculate the singleton mask among the ranges, if any.
2731 wide_int lower_bound
, upper_bound
, mask
;
2732 if (wi::eq_p (rh_lb
, rh_ub
))
2735 lower_bound
= lh_lb
;
2736 upper_bound
= lh_ub
;
2738 else if (wi::eq_p (lh_lb
, lh_ub
))
2741 lower_bound
= rh_lb
;
2742 upper_bound
= rh_ub
;
2747 // If Z is a constant which (for op | its bitwise not) has n
2748 // consecutive least significant bits cleared followed by m 1
2749 // consecutive bits set immediately above it and either
2750 // m + n == precision, or (x >> (m + n)) == (y >> (m + n)).
2752 // The least significant n bits of all the values in the range are
2753 // cleared or set, the m bits above it are preserved and any bits
2754 // above these are required to be the same for all values in the
2758 if (code
== BIT_IOR_EXPR
)
2760 if (wi::eq_p (w
, 0))
2761 n
= w
.get_precision ();
2765 w
= ~(w
| wi::mask (n
, false, w
.get_precision ()));
2766 if (wi::eq_p (w
, 0))
2767 m
= w
.get_precision () - n
;
2769 m
= wi::ctz (w
) - n
;
2771 wide_int new_mask
= wi::mask (m
+ n
, true, w
.get_precision ());
2772 if ((new_mask
& lower_bound
) != (new_mask
& upper_bound
))
2775 wide_int res_lb
, res_ub
;
2776 if (code
== BIT_AND_EXPR
)
2778 res_lb
= wi::bit_and (lower_bound
, mask
);
2779 res_ub
= wi::bit_and (upper_bound
, mask
);
2781 else if (code
== BIT_IOR_EXPR
)
2783 res_lb
= wi::bit_or (lower_bound
, mask
);
2784 res_ub
= wi::bit_or (upper_bound
, mask
);
2788 value_range_with_overflow (r
, type
, res_lb
, res_ub
);
2790 // Furthermore, if the mask is non-zero, an IOR cannot contain zero.
2791 if (code
== BIT_IOR_EXPR
&& wi::ne_p (mask
, 0))
2794 tmp
.set_nonzero (type
);
2800 // For range [LB, UB] compute two wide_int bit masks.
2802 // In the MAYBE_NONZERO bit mask, if some bit is unset, it means that
2803 // for all numbers in the range the bit is 0, otherwise it might be 0
2806 // In the MUSTBE_NONZERO bit mask, if some bit is set, it means that
2807 // for all numbers in the range the bit is 1, otherwise it might be 0
2811 wi_set_zero_nonzero_bits (tree type
,
2812 const wide_int
&lb
, const wide_int
&ub
,
2813 wide_int
&maybe_nonzero
,
2814 wide_int
&mustbe_nonzero
)
2816 signop sign
= TYPE_SIGN (type
);
2818 if (wi::eq_p (lb
, ub
))
2819 maybe_nonzero
= mustbe_nonzero
= lb
;
2820 else if (wi::ge_p (lb
, 0, sign
) || wi::lt_p (ub
, 0, sign
))
2822 wide_int xor_mask
= lb
^ ub
;
2823 maybe_nonzero
= lb
| ub
;
2824 mustbe_nonzero
= lb
& ub
;
2827 wide_int mask
= wi::mask (wi::floor_log2 (xor_mask
), false,
2828 maybe_nonzero
.get_precision ());
2829 maybe_nonzero
= maybe_nonzero
| mask
;
2830 mustbe_nonzero
= wi::bit_and_not (mustbe_nonzero
, mask
);
2835 maybe_nonzero
= wi::minus_one (lb
.get_precision ());
2836 mustbe_nonzero
= wi::zero (lb
.get_precision ());
2841 operator_bitwise_and::wi_fold (irange
&r
, tree type
,
2842 const wide_int
&lh_lb
,
2843 const wide_int
&lh_ub
,
2844 const wide_int
&rh_lb
,
2845 const wide_int
&rh_ub
) const
2847 if (wi_optimize_and_or (r
, BIT_AND_EXPR
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
))
2850 wide_int maybe_nonzero_lh
, mustbe_nonzero_lh
;
2851 wide_int maybe_nonzero_rh
, mustbe_nonzero_rh
;
2852 wi_set_zero_nonzero_bits (type
, lh_lb
, lh_ub
,
2853 maybe_nonzero_lh
, mustbe_nonzero_lh
);
2854 wi_set_zero_nonzero_bits (type
, rh_lb
, rh_ub
,
2855 maybe_nonzero_rh
, mustbe_nonzero_rh
);
2857 wide_int new_lb
= mustbe_nonzero_lh
& mustbe_nonzero_rh
;
2858 wide_int new_ub
= maybe_nonzero_lh
& maybe_nonzero_rh
;
2859 signop sign
= TYPE_SIGN (type
);
2860 unsigned prec
= TYPE_PRECISION (type
);
2861 // If both input ranges contain only negative values, we can
2862 // truncate the result range maximum to the minimum of the
2863 // input range maxima.
2864 if (wi::lt_p (lh_ub
, 0, sign
) && wi::lt_p (rh_ub
, 0, sign
))
2866 new_ub
= wi::min (new_ub
, lh_ub
, sign
);
2867 new_ub
= wi::min (new_ub
, rh_ub
, sign
);
2869 // If either input range contains only non-negative values
2870 // we can truncate the result range maximum to the respective
2871 // maximum of the input range.
2872 if (wi::ge_p (lh_lb
, 0, sign
))
2873 new_ub
= wi::min (new_ub
, lh_ub
, sign
);
2874 if (wi::ge_p (rh_lb
, 0, sign
))
2875 new_ub
= wi::min (new_ub
, rh_ub
, sign
);
2876 // PR68217: In case of signed & sign-bit-CST should
2877 // result in [-INF, 0] instead of [-INF, INF].
2878 if (wi::gt_p (new_lb
, new_ub
, sign
))
2880 wide_int sign_bit
= wi::set_bit_in_zero (prec
- 1, prec
);
2882 && ((wi::eq_p (lh_lb
, lh_ub
)
2883 && !wi::cmps (lh_lb
, sign_bit
))
2884 || (wi::eq_p (rh_lb
, rh_ub
)
2885 && !wi::cmps (rh_lb
, sign_bit
))))
2887 new_lb
= wi::min_value (prec
, sign
);
2888 new_ub
= wi::zero (prec
);
2891 // If the limits got swapped around, return varying.
2892 if (wi::gt_p (new_lb
, new_ub
,sign
))
2895 && wi_optimize_signed_bitwise_op (r
, type
,
2899 r
.set_varying (type
);
2902 value_range_with_overflow (r
, type
, new_lb
, new_ub
);
2906 set_nonzero_range_from_mask (irange
&r
, tree type
, const irange
&lhs
)
2908 if (!lhs
.contains_p (build_zero_cst (type
)))
2909 r
= range_nonzero (type
);
2911 r
.set_varying (type
);
2914 // This was shamelessly stolen from register_edge_assert_for_2 and
2915 // adjusted to work with iranges.
2918 operator_bitwise_and::simple_op1_range_solver (irange
&r
, tree type
,
2920 const irange
&op2
) const
2922 if (!op2
.singleton_p ())
2924 set_nonzero_range_from_mask (r
, type
, lhs
);
2927 unsigned int nprec
= TYPE_PRECISION (type
);
2928 wide_int cst2v
= op2
.lower_bound ();
2929 bool cst2n
= wi::neg_p (cst2v
, TYPE_SIGN (type
));
2932 sgnbit
= wi::set_bit_in_zero (nprec
- 1, nprec
);
2934 sgnbit
= wi::zero (nprec
);
2936 // Solve [lhs.lower_bound (), +INF] = x & MASK.
2938 // Minimum unsigned value for >= if (VAL & CST2) == VAL is VAL and
2939 // maximum unsigned value is ~0. For signed comparison, if CST2
2940 // doesn't have the most significant bit set, handle it similarly. If
2941 // CST2 has MSB set, the minimum is the same, and maximum is ~0U/2.
2942 wide_int valv
= lhs
.lower_bound ();
2943 wide_int minv
= valv
& cst2v
, maxv
;
2944 bool we_know_nothing
= false;
2947 // If (VAL & CST2) != VAL, X & CST2 can't be equal to VAL.
2948 minv
= masked_increment (valv
, cst2v
, sgnbit
, nprec
);
2951 // If we can't determine anything on this bound, fall
2952 // through and conservatively solve for the other end point.
2953 we_know_nothing
= true;
2956 maxv
= wi::mask (nprec
- (cst2n
? 1 : 0), false, nprec
);
2957 if (we_know_nothing
)
2958 r
.set_varying (type
);
2960 r
= int_range
<1> (type
, minv
, maxv
);
2962 // Solve [-INF, lhs.upper_bound ()] = x & MASK.
2964 // Minimum unsigned value for <= is 0 and maximum unsigned value is
2965 // VAL | ~CST2 if (VAL & CST2) == VAL. Otherwise, find smallest
2967 // VAL2 > VAL && (VAL2 & CST2) == VAL2 and use (VAL2 - 1) | ~CST2
2969 // For signed comparison, if CST2 doesn't have most significant bit
2970 // set, handle it similarly. If CST2 has MSB set, the maximum is
2971 // the same and minimum is INT_MIN.
2972 valv
= lhs
.upper_bound ();
2973 minv
= valv
& cst2v
;
2978 maxv
= masked_increment (valv
, cst2v
, sgnbit
, nprec
);
2981 // If we couldn't determine anything on either bound, return
2983 if (we_know_nothing
)
2991 int_range
<1> upper_bits (type
, minv
, maxv
);
2992 r
.intersect (upper_bits
);
2996 operator_bitwise_and::op1_range (irange
&r
, tree type
,
2999 relation_kind rel ATTRIBUTE_UNUSED
) const
3001 if (types_compatible_p (type
, boolean_type_node
))
3002 return op_logical_and
.op1_range (r
, type
, lhs
, op2
);
3005 for (unsigned i
= 0; i
< lhs
.num_pairs (); ++i
)
3007 int_range_max
chunk (lhs
.type (),
3008 lhs
.lower_bound (i
),
3009 lhs
.upper_bound (i
));
3011 simple_op1_range_solver (res
, type
, chunk
, op2
);
3014 if (r
.undefined_p ())
3015 set_nonzero_range_from_mask (r
, type
, lhs
);
3020 operator_bitwise_and::op2_range (irange
&r
, tree type
,
3023 relation_kind rel ATTRIBUTE_UNUSED
) const
3025 return operator_bitwise_and::op1_range (r
, type
, lhs
, op1
);
3029 class operator_logical_or
: public range_operator
3031 using range_operator::fold_range
;
3032 using range_operator::op1_range
;
3033 using range_operator::op2_range
;
3035 virtual bool fold_range (irange
&r
, tree type
,
3038 relation_kind rel
= VREL_VARYING
) const;
3039 virtual bool op1_range (irange
&r
, tree type
,
3042 relation_kind rel
= VREL_VARYING
) const;
3043 virtual bool op2_range (irange
&r
, tree type
,
3046 relation_kind rel
= VREL_VARYING
) const;
3050 operator_logical_or::fold_range (irange
&r
, tree type ATTRIBUTE_UNUSED
,
3053 relation_kind rel ATTRIBUTE_UNUSED
) const
3055 if (empty_range_varying (r
, type
, lh
, rh
))
3064 operator_logical_or::op1_range (irange
&r
, tree type
,
3066 const irange
&op2 ATTRIBUTE_UNUSED
,
3067 relation_kind rel ATTRIBUTE_UNUSED
) const
3069 switch (get_bool_state (r
, lhs
, type
))
3072 // A false result means both sides of the OR must be false.
3073 r
= range_false (type
);
3076 // Any other result means only one side has to be true, the
3077 // other side can be anything. so we can't be sure of any result
3079 r
= range_true_and_false (type
);
3086 operator_logical_or::op2_range (irange
&r
, tree type
,
3089 relation_kind rel ATTRIBUTE_UNUSED
) const
3091 return operator_logical_or::op1_range (r
, type
, lhs
, op1
);
3095 class operator_bitwise_or
: public range_operator
3097 using range_operator::op1_range
;
3098 using range_operator::op2_range
;
3100 virtual bool op1_range (irange
&r
, tree type
,
3103 relation_kind rel
= VREL_VARYING
) const;
3104 virtual bool op2_range (irange
&r
, tree type
,
3107 relation_kind rel
= VREL_VARYING
) const;
3108 virtual void wi_fold (irange
&r
, tree type
,
3109 const wide_int
&lh_lb
,
3110 const wide_int
&lh_ub
,
3111 const wide_int
&rh_lb
,
3112 const wide_int
&rh_ub
) const;
3116 operator_bitwise_or::wi_fold (irange
&r
, tree type
,
3117 const wide_int
&lh_lb
,
3118 const wide_int
&lh_ub
,
3119 const wide_int
&rh_lb
,
3120 const wide_int
&rh_ub
) const
3122 if (wi_optimize_and_or (r
, BIT_IOR_EXPR
, type
, lh_lb
, lh_ub
, rh_lb
, rh_ub
))
3125 wide_int maybe_nonzero_lh
, mustbe_nonzero_lh
;
3126 wide_int maybe_nonzero_rh
, mustbe_nonzero_rh
;
3127 wi_set_zero_nonzero_bits (type
, lh_lb
, lh_ub
,
3128 maybe_nonzero_lh
, mustbe_nonzero_lh
);
3129 wi_set_zero_nonzero_bits (type
, rh_lb
, rh_ub
,
3130 maybe_nonzero_rh
, mustbe_nonzero_rh
);
3131 wide_int new_lb
= mustbe_nonzero_lh
| mustbe_nonzero_rh
;
3132 wide_int new_ub
= maybe_nonzero_lh
| maybe_nonzero_rh
;
3133 signop sign
= TYPE_SIGN (type
);
3134 // If the input ranges contain only positive values we can
3135 // truncate the minimum of the result range to the maximum
3136 // of the input range minima.
3137 if (wi::ge_p (lh_lb
, 0, sign
)
3138 && wi::ge_p (rh_lb
, 0, sign
))
3140 new_lb
= wi::max (new_lb
, lh_lb
, sign
);
3141 new_lb
= wi::max (new_lb
, rh_lb
, sign
);
3143 // If either input range contains only negative values
3144 // we can truncate the minimum of the result range to the
3145 // respective minimum range.
3146 if (wi::lt_p (lh_ub
, 0, sign
))
3147 new_lb
= wi::max (new_lb
, lh_lb
, sign
);
3148 if (wi::lt_p (rh_ub
, 0, sign
))
3149 new_lb
= wi::max (new_lb
, rh_lb
, sign
);
3150 // If the limits got swapped around, return a conservative range.
3151 if (wi::gt_p (new_lb
, new_ub
, sign
))
3153 // Make sure that nonzero|X is nonzero.
3154 if (wi::gt_p (lh_lb
, 0, sign
)
3155 || wi::gt_p (rh_lb
, 0, sign
)
3156 || wi::lt_p (lh_ub
, 0, sign
)
3157 || wi::lt_p (rh_ub
, 0, sign
))
3158 r
.set_nonzero (type
);
3159 else if (sign
== SIGNED
3160 && wi_optimize_signed_bitwise_op (r
, type
,
3165 r
.set_varying (type
);
3168 value_range_with_overflow (r
, type
, new_lb
, new_ub
);
3172 operator_bitwise_or::op1_range (irange
&r
, tree type
,
3175 relation_kind rel ATTRIBUTE_UNUSED
) const
3177 // If this is really a logical wi_fold, call that.
3178 if (types_compatible_p (type
, boolean_type_node
))
3179 return op_logical_or
.op1_range (r
, type
, lhs
, op2
);
3183 tree zero
= build_zero_cst (type
);
3184 r
= int_range
<1> (zero
, zero
);
3187 r
.set_varying (type
);
3192 operator_bitwise_or::op2_range (irange
&r
, tree type
,
3195 relation_kind rel ATTRIBUTE_UNUSED
) const
3197 return operator_bitwise_or::op1_range (r
, type
, lhs
, op1
);
3201 class operator_bitwise_xor
: public range_operator
3203 using range_operator::op1_range
;
3204 using range_operator::op2_range
;
3206 virtual void wi_fold (irange
&r
, tree type
,
3207 const wide_int
&lh_lb
,
3208 const wide_int
&lh_ub
,
3209 const wide_int
&rh_lb
,
3210 const wide_int
&rh_ub
) const;
3211 virtual bool op1_range (irange
&r
, tree type
,
3214 relation_kind rel
= VREL_VARYING
) const;
3215 virtual bool op2_range (irange
&r
, tree type
,
3218 relation_kind rel
= VREL_VARYING
) const;
3219 virtual bool op1_op2_relation_effect (irange
&lhs_range
,
3221 const irange
&op1_range
,
3222 const irange
&op2_range
,
3223 relation_kind rel
) const;
3227 operator_bitwise_xor::wi_fold (irange
&r
, tree type
,
3228 const wide_int
&lh_lb
,
3229 const wide_int
&lh_ub
,
3230 const wide_int
&rh_lb
,
3231 const wide_int
&rh_ub
) const
3233 signop sign
= TYPE_SIGN (type
);
3234 wide_int maybe_nonzero_lh
, mustbe_nonzero_lh
;
3235 wide_int maybe_nonzero_rh
, mustbe_nonzero_rh
;
3236 wi_set_zero_nonzero_bits (type
, lh_lb
, lh_ub
,
3237 maybe_nonzero_lh
, mustbe_nonzero_lh
);
3238 wi_set_zero_nonzero_bits (type
, rh_lb
, rh_ub
,
3239 maybe_nonzero_rh
, mustbe_nonzero_rh
);
3241 wide_int result_zero_bits
= ((mustbe_nonzero_lh
& mustbe_nonzero_rh
)
3242 | ~(maybe_nonzero_lh
| maybe_nonzero_rh
));
3243 wide_int result_one_bits
3244 = (wi::bit_and_not (mustbe_nonzero_lh
, maybe_nonzero_rh
)
3245 | wi::bit_and_not (mustbe_nonzero_rh
, maybe_nonzero_lh
));
3246 wide_int new_ub
= ~result_zero_bits
;
3247 wide_int new_lb
= result_one_bits
;
3249 // If the range has all positive or all negative values, the result
3250 // is better than VARYING.
3251 if (wi::lt_p (new_lb
, 0, sign
) || wi::ge_p (new_ub
, 0, sign
))
3252 value_range_with_overflow (r
, type
, new_lb
, new_ub
);
3253 else if (sign
== SIGNED
3254 && wi_optimize_signed_bitwise_op (r
, type
,
3259 r
.set_varying (type
);
3261 /* Furthermore, XOR is non-zero if its arguments can't be equal. */
3262 if (wi::lt_p (lh_ub
, rh_lb
, sign
)
3263 || wi::lt_p (rh_ub
, lh_lb
, sign
)
3264 || wi::ne_p (result_one_bits
, 0))
3267 tmp
.set_nonzero (type
);
3273 operator_bitwise_xor::op1_op2_relation_effect (irange
&lhs_range
,
3277 relation_kind rel
) const
3279 if (rel
== VREL_VARYING
)
3282 int_range
<2> rel_range
;
3287 rel_range
.set_zero (type
);
3290 rel_range
.set_nonzero (type
);
3296 lhs_range
.intersect (rel_range
);
3301 operator_bitwise_xor::op1_range (irange
&r
, tree type
,
3304 relation_kind rel ATTRIBUTE_UNUSED
) const
3306 if (lhs
.undefined_p () || lhs
.varying_p ())
3311 if (types_compatible_p (type
, boolean_type_node
))
3313 switch (get_bool_state (r
, lhs
, type
))
3316 if (op2
.varying_p ())
3317 r
.set_varying (type
);
3318 else if (op2
.zero_p ())
3319 r
= range_true (type
);
3321 r
= range_false (type
);
3331 r
.set_varying (type
);
3336 operator_bitwise_xor::op2_range (irange
&r
, tree type
,
3339 relation_kind rel ATTRIBUTE_UNUSED
) const
3341 return operator_bitwise_xor::op1_range (r
, type
, lhs
, op1
);
3344 class operator_trunc_mod
: public range_operator
3346 using range_operator::op1_range
;
3347 using range_operator::op2_range
;
3349 virtual void wi_fold (irange
&r
, tree type
,
3350 const wide_int
&lh_lb
,
3351 const wide_int
&lh_ub
,
3352 const wide_int
&rh_lb
,
3353 const wide_int
&rh_ub
) const;
3354 virtual bool op1_range (irange
&r
, tree type
,
3357 relation_kind rel ATTRIBUTE_UNUSED
) const;
3358 virtual bool op2_range (irange
&r
, tree type
,
3361 relation_kind rel ATTRIBUTE_UNUSED
) const;
3365 operator_trunc_mod::wi_fold (irange
&r
, tree type
,
3366 const wide_int
&lh_lb
,
3367 const wide_int
&lh_ub
,
3368 const wide_int
&rh_lb
,
3369 const wide_int
&rh_ub
) const
3371 wide_int new_lb
, new_ub
, tmp
;
3372 signop sign
= TYPE_SIGN (type
);
3373 unsigned prec
= TYPE_PRECISION (type
);
3375 // Mod 0 is undefined.
3376 if (wi_zero_p (type
, rh_lb
, rh_ub
))
3382 // Check for constant and try to fold.
3383 if (lh_lb
== lh_ub
&& rh_lb
== rh_ub
)
3385 wi::overflow_type ov
= wi::OVF_NONE
;
3386 tmp
= wi::mod_trunc (lh_lb
, rh_lb
, sign
, &ov
);
3387 if (ov
== wi::OVF_NONE
)
3389 r
= int_range
<2> (type
, tmp
, tmp
);
3394 // ABS (A % B) < ABS (B) and either 0 <= A % B <= A or A <= A % B <= 0.
3399 new_ub
= wi::smax (new_ub
, tmp
);
3402 if (sign
== UNSIGNED
)
3403 new_lb
= wi::zero (prec
);
3408 if (wi::gts_p (tmp
, 0))
3409 tmp
= wi::zero (prec
);
3410 new_lb
= wi::smax (new_lb
, tmp
);
3413 if (sign
== SIGNED
&& wi::neg_p (tmp
))
3414 tmp
= wi::zero (prec
);
3415 new_ub
= wi::min (new_ub
, tmp
, sign
);
3417 value_range_with_overflow (r
, type
, new_lb
, new_ub
);
3421 operator_trunc_mod::op1_range (irange
&r
, tree type
,
3424 relation_kind rel ATTRIBUTE_UNUSED
) const
3427 signop sign
= TYPE_SIGN (type
);
3428 unsigned prec
= TYPE_PRECISION (type
);
3429 // (a % b) >= x && x > 0 , then a >= x.
3430 if (wi::gt_p (lhs
.lower_bound (), 0, sign
))
3432 r
= value_range (type
, lhs
.lower_bound (), wi::max_value (prec
, sign
));
3435 // (a % b) <= x && x < 0 , then a <= x.
3436 if (wi::lt_p (lhs
.upper_bound (), 0, sign
))
3438 r
= value_range (type
, wi::min_value (prec
, sign
), lhs
.upper_bound ());
3445 operator_trunc_mod::op2_range (irange
&r
, tree type
,
3448 relation_kind rel ATTRIBUTE_UNUSED
) const
3451 signop sign
= TYPE_SIGN (type
);
3452 unsigned prec
= TYPE_PRECISION (type
);
3453 // (a % b) >= x && x > 0 , then b is in ~[-x, x] for signed
3454 // or b > x for unsigned.
3455 if (wi::gt_p (lhs
.lower_bound (), 0, sign
))
3458 r
= value_range (type
, wi::neg (lhs
.lower_bound ()),
3459 lhs
.lower_bound (), VR_ANTI_RANGE
);
3460 else if (wi::lt_p (lhs
.lower_bound (), wi::max_value (prec
, sign
),
3462 r
= value_range (type
, lhs
.lower_bound () + 1,
3463 wi::max_value (prec
, sign
));
3468 // (a % b) <= x && x < 0 , then b is in ~[x, -x].
3469 if (wi::lt_p (lhs
.upper_bound (), 0, sign
))
3471 if (wi::gt_p (lhs
.upper_bound (), wi::min_value (prec
, sign
), sign
))
3472 r
= value_range (type
, lhs
.upper_bound (),
3473 wi::neg (lhs
.upper_bound ()), VR_ANTI_RANGE
);
3482 class operator_logical_not
: public range_operator
3484 using range_operator::fold_range
;
3485 using range_operator::op1_range
;
3487 virtual bool fold_range (irange
&r
, tree type
,
3490 relation_kind rel
= VREL_VARYING
) const;
3491 virtual bool op1_range (irange
&r
, tree type
,
3494 relation_kind rel
= VREL_VARYING
) const;
3497 // Folding a logical NOT, oddly enough, involves doing nothing on the
3498 // forward pass through. During the initial walk backwards, the
3499 // logical NOT reversed the desired outcome on the way back, so on the
3500 // way forward all we do is pass the range forward.
3505 // to determine the TRUE branch, walking backward
3506 // if (b_3) if ([1,1])
3507 // b_3 = !b_2 [1,1] = ![0,0]
3508 // b_2 = x_1 < 20 [0,0] = x_1 < 20, false, so x_1 == [20, 255]
3509 // which is the result we are looking for.. so.. pass it through.
3512 operator_logical_not::fold_range (irange
&r
, tree type
,
3514 const irange
&rh ATTRIBUTE_UNUSED
,
3515 relation_kind rel ATTRIBUTE_UNUSED
) const
3517 if (empty_range_varying (r
, type
, lh
, rh
))
3521 if (!lh
.varying_p () && !lh
.undefined_p ())
3528 operator_logical_not::op1_range (irange
&r
,
3532 relation_kind rel ATTRIBUTE_UNUSED
) const
3534 // Logical NOT is involutary...do it again.
3535 return fold_range (r
, type
, lhs
, op2
);
3539 class operator_bitwise_not
: public range_operator
3541 using range_operator::fold_range
;
3542 using range_operator::op1_range
;
3544 virtual bool fold_range (irange
&r
, tree type
,
3547 relation_kind rel
= VREL_VARYING
) const;
3548 virtual bool op1_range (irange
&r
, tree type
,
3551 relation_kind rel
= VREL_VARYING
) const;
3555 operator_bitwise_not::fold_range (irange
&r
, tree type
,
3558 relation_kind rel ATTRIBUTE_UNUSED
) const
3560 if (empty_range_varying (r
, type
, lh
, rh
))
3563 if (types_compatible_p (type
, boolean_type_node
))
3564 return op_logical_not
.fold_range (r
, type
, lh
, rh
);
3566 // ~X is simply -1 - X.
3567 int_range
<1> minusone (type
, wi::minus_one (TYPE_PRECISION (type
)),
3568 wi::minus_one (TYPE_PRECISION (type
)));
3569 return range_op_handler (MINUS_EXPR
, type
).fold_range (r
, type
, minusone
, lh
);
3573 operator_bitwise_not::op1_range (irange
&r
, tree type
,
3576 relation_kind rel ATTRIBUTE_UNUSED
) const
3578 if (types_compatible_p (type
, boolean_type_node
))
3579 return op_logical_not
.op1_range (r
, type
, lhs
, op2
);
3581 // ~X is -1 - X and since bitwise NOT is involutary...do it again.
3582 return fold_range (r
, type
, lhs
, op2
);
3586 class operator_cst
: public range_operator
3588 using range_operator::fold_range
;
3590 virtual bool fold_range (irange
&r
, tree type
,
3593 relation_kind rel
= VREL_VARYING
) const;
3597 operator_cst::fold_range (irange
&r
, tree type ATTRIBUTE_UNUSED
,
3599 const irange
&rh ATTRIBUTE_UNUSED
,
3600 relation_kind rel ATTRIBUTE_UNUSED
) const
3607 class operator_identity
: public range_operator
3609 using range_operator::fold_range
;
3610 using range_operator::op1_range
;
3611 using range_operator::lhs_op1_relation
;
3613 virtual bool fold_range (irange
&r
, tree type
,
3616 relation_kind rel
= VREL_VARYING
) const;
3617 virtual bool op1_range (irange
&r
, tree type
,
3620 relation_kind rel
= VREL_VARYING
) const;
3621 virtual relation_kind
lhs_op1_relation (const irange
&lhs
,
3624 relation_kind rel
) const;
3627 // Determine if there is a relationship between LHS and OP1.
3630 operator_identity::lhs_op1_relation (const irange
&lhs
,
3631 const irange
&op1 ATTRIBUTE_UNUSED
,
3632 const irange
&op2 ATTRIBUTE_UNUSED
,
3633 relation_kind
) const
3635 if (lhs
.undefined_p ())
3636 return VREL_VARYING
;
3637 // Simply a copy, so they are equivalent.
3642 operator_identity::fold_range (irange
&r
, tree type ATTRIBUTE_UNUSED
,
3644 const irange
&rh ATTRIBUTE_UNUSED
,
3645 relation_kind rel ATTRIBUTE_UNUSED
) const
3652 operator_identity::op1_range (irange
&r
, tree type ATTRIBUTE_UNUSED
,
3654 const irange
&op2 ATTRIBUTE_UNUSED
,
3655 relation_kind rel ATTRIBUTE_UNUSED
) const
3662 class operator_unknown
: public range_operator
3664 using range_operator::fold_range
;
3666 virtual bool fold_range (irange
&r
, tree type
,
3669 relation_kind rel
= VREL_VARYING
) const;
3673 operator_unknown::fold_range (irange
&r
, tree type
,
3674 const irange
&lh ATTRIBUTE_UNUSED
,
3675 const irange
&rh ATTRIBUTE_UNUSED
,
3676 relation_kind rel ATTRIBUTE_UNUSED
) const
3678 r
.set_varying (type
);
3683 class operator_abs
: public range_operator
3685 using range_operator::op1_range
;
3687 virtual void wi_fold (irange
&r
, tree type
,
3688 const wide_int
&lh_lb
,
3689 const wide_int
&lh_ub
,
3690 const wide_int
&rh_lb
,
3691 const wide_int
&rh_ub
) const;
3692 virtual bool op1_range (irange
&r
, tree type
,
3695 relation_kind rel ATTRIBUTE_UNUSED
) const;
3699 operator_abs::wi_fold (irange
&r
, tree type
,
3700 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
3701 const wide_int
&rh_lb ATTRIBUTE_UNUSED
,
3702 const wide_int
&rh_ub ATTRIBUTE_UNUSED
) const
3705 signop sign
= TYPE_SIGN (type
);
3706 unsigned prec
= TYPE_PRECISION (type
);
3708 // Pass through LH for the easy cases.
3709 if (sign
== UNSIGNED
|| wi::ge_p (lh_lb
, 0, sign
))
3711 r
= int_range
<1> (type
, lh_lb
, lh_ub
);
3715 // -TYPE_MIN_VALUE = TYPE_MIN_VALUE with flag_wrapv so we can't get
3717 wide_int min_value
= wi::min_value (prec
, sign
);
3718 wide_int max_value
= wi::max_value (prec
, sign
);
3719 if (!TYPE_OVERFLOW_UNDEFINED (type
) && wi::eq_p (lh_lb
, min_value
))
3721 r
.set_varying (type
);
3725 // ABS_EXPR may flip the range around, if the original range
3726 // included negative values.
3727 if (wi::eq_p (lh_lb
, min_value
))
3729 // ABS ([-MIN, -MIN]) isn't representable, but we have traditionally
3730 // returned [-MIN,-MIN] so this preserves that behaviour. PR37078
3731 if (wi::eq_p (lh_ub
, min_value
))
3733 r
= int_range
<1> (type
, min_value
, min_value
);
3739 min
= wi::abs (lh_lb
);
3741 if (wi::eq_p (lh_ub
, min_value
))
3744 max
= wi::abs (lh_ub
);
3746 // If the range contains zero then we know that the minimum value in the
3747 // range will be zero.
3748 if (wi::le_p (lh_lb
, 0, sign
) && wi::ge_p (lh_ub
, 0, sign
))
3750 if (wi::gt_p (min
, max
, sign
))
3752 min
= wi::zero (prec
);
3756 // If the range was reversed, swap MIN and MAX.
3757 if (wi::gt_p (min
, max
, sign
))
3758 std::swap (min
, max
);
3761 // If the new range has its limits swapped around (MIN > MAX), then
3762 // the operation caused one of them to wrap around. The only thing
3763 // we know is that the result is positive.
3764 if (wi::gt_p (min
, max
, sign
))
3766 min
= wi::zero (prec
);
3769 r
= int_range
<1> (type
, min
, max
);
3773 operator_abs::op1_range (irange
&r
, tree type
,
3776 relation_kind rel ATTRIBUTE_UNUSED
) const
3778 if (empty_range_varying (r
, type
, lhs
, op2
))
3780 if (TYPE_UNSIGNED (type
))
3785 // Start with the positives because negatives are an impossible result.
3786 int_range_max positives
= range_positives (type
);
3787 positives
.intersect (lhs
);
3789 // Then add the negative of each pair:
3790 // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20].
3791 for (unsigned i
= 0; i
< positives
.num_pairs (); ++i
)
3792 r
.union_ (int_range
<1> (type
,
3793 -positives
.upper_bound (i
),
3794 -positives
.lower_bound (i
)));
3795 // With flag_wrapv, -TYPE_MIN_VALUE = TYPE_MIN_VALUE which is
3796 // unrepresentable. Add -TYPE_MIN_VALUE in this case.
3797 wide_int min_value
= wi::min_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
3798 wide_int lb
= lhs
.lower_bound ();
3799 if (!TYPE_OVERFLOW_UNDEFINED (type
) && wi::eq_p (lb
, min_value
))
3800 r
.union_ (int_range
<2> (type
, lb
, lb
));
3805 class operator_absu
: public range_operator
3808 virtual void wi_fold (irange
&r
, tree type
,
3809 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
3810 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const;
3814 operator_absu::wi_fold (irange
&r
, tree type
,
3815 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
3816 const wide_int
&rh_lb ATTRIBUTE_UNUSED
,
3817 const wide_int
&rh_ub ATTRIBUTE_UNUSED
) const
3819 wide_int new_lb
, new_ub
;
3821 // Pass through VR0 the easy cases.
3822 if (wi::ges_p (lh_lb
, 0))
3829 new_lb
= wi::abs (lh_lb
);
3830 new_ub
= wi::abs (lh_ub
);
3832 // If the range contains zero then we know that the minimum
3833 // value in the range will be zero.
3834 if (wi::ges_p (lh_ub
, 0))
3836 if (wi::gtu_p (new_lb
, new_ub
))
3838 new_lb
= wi::zero (TYPE_PRECISION (type
));
3841 std::swap (new_lb
, new_ub
);
3844 gcc_checking_assert (TYPE_UNSIGNED (type
));
3845 r
= int_range
<1> (type
, new_lb
, new_ub
);
3849 class operator_negate
: public range_operator
3851 using range_operator::fold_range
;
3852 using range_operator::op1_range
;
3854 virtual bool fold_range (irange
&r
, tree type
,
3857 relation_kind rel
= VREL_VARYING
) const;
3858 virtual bool op1_range (irange
&r
, tree type
,
3861 relation_kind rel
= VREL_VARYING
) const;
3865 operator_negate::fold_range (irange
&r
, tree type
,
3868 relation_kind rel ATTRIBUTE_UNUSED
) const
3870 if (empty_range_varying (r
, type
, lh
, rh
))
3872 // -X is simply 0 - X.
3873 return range_op_handler (MINUS_EXPR
, type
).fold_range (r
, type
,
3874 range_zero (type
), lh
);
3878 operator_negate::op1_range (irange
&r
, tree type
,
3881 relation_kind rel ATTRIBUTE_UNUSED
) const
3883 // NEGATE is involutory.
3884 return fold_range (r
, type
, lhs
, op2
);
3888 class operator_addr_expr
: public range_operator
3890 using range_operator::fold_range
;
3891 using range_operator::op1_range
;
3893 virtual bool fold_range (irange
&r
, tree type
,
3896 relation_kind rel
= VREL_VARYING
) const;
3897 virtual bool op1_range (irange
&r
, tree type
,
3900 relation_kind rel
= VREL_VARYING
) const;
3904 operator_addr_expr::fold_range (irange
&r
, tree type
,
3907 relation_kind rel ATTRIBUTE_UNUSED
) const
3909 if (empty_range_varying (r
, type
, lh
, rh
))
3912 // Return a non-null pointer of the LHS type (passed in op2).
3914 r
= range_zero (type
);
3915 else if (!lh
.contains_p (build_zero_cst (lh
.type ())))
3916 r
= range_nonzero (type
);
3918 r
.set_varying (type
);
3923 operator_addr_expr::op1_range (irange
&r
, tree type
,
3926 relation_kind rel ATTRIBUTE_UNUSED
) const
3928 return operator_addr_expr::fold_range (r
, type
, lhs
, op2
);
3932 class pointer_plus_operator
: public range_operator
3935 virtual void wi_fold (irange
&r
, tree type
,
3936 const wide_int
&lh_lb
,
3937 const wide_int
&lh_ub
,
3938 const wide_int
&rh_lb
,
3939 const wide_int
&rh_ub
) const;
3943 pointer_plus_operator::wi_fold (irange
&r
, tree type
,
3944 const wide_int
&lh_lb
,
3945 const wide_int
&lh_ub
,
3946 const wide_int
&rh_lb
,
3947 const wide_int
&rh_ub
) const
3949 // Check for [0,0] + const, and simply return the const.
3950 if (lh_lb
== 0 && lh_ub
== 0 && rh_lb
== rh_ub
)
3952 tree val
= wide_int_to_tree (type
, rh_lb
);
3957 // For pointer types, we are really only interested in asserting
3958 // whether the expression evaluates to non-NULL.
3960 // With -fno-delete-null-pointer-checks we need to be more
3961 // conservative. As some object might reside at address 0,
3962 // then some offset could be added to it and the same offset
3963 // subtracted again and the result would be NULL.
3965 // static int a[12]; where &a[0] is NULL and
3968 // ptr will be NULL here, even when there is POINTER_PLUS_EXPR
3969 // where the first range doesn't include zero and the second one
3970 // doesn't either. As the second operand is sizetype (unsigned),
3971 // consider all ranges where the MSB could be set as possible
3972 // subtractions where the result might be NULL.
3973 if ((!wi_includes_zero_p (type
, lh_lb
, lh_ub
)
3974 || !wi_includes_zero_p (type
, rh_lb
, rh_ub
))
3975 && !TYPE_OVERFLOW_WRAPS (type
)
3976 && (flag_delete_null_pointer_checks
3977 || !wi::sign_mask (rh_ub
)))
3978 r
= range_nonzero (type
);
3979 else if (lh_lb
== lh_ub
&& lh_lb
== 0
3980 && rh_lb
== rh_ub
&& rh_lb
== 0)
3981 r
= range_zero (type
);
3983 r
.set_varying (type
);
3987 class pointer_min_max_operator
: public range_operator
3990 virtual void wi_fold (irange
& r
, tree type
,
3991 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
3992 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const;
3996 pointer_min_max_operator::wi_fold (irange
&r
, tree type
,
3997 const wide_int
&lh_lb
,
3998 const wide_int
&lh_ub
,
3999 const wide_int
&rh_lb
,
4000 const wide_int
&rh_ub
) const
4002 // For MIN/MAX expressions with pointers, we only care about
4003 // nullness. If both are non null, then the result is nonnull.
4004 // If both are null, then the result is null. Otherwise they
4006 if (!wi_includes_zero_p (type
, lh_lb
, lh_ub
)
4007 && !wi_includes_zero_p (type
, rh_lb
, rh_ub
))
4008 r
= range_nonzero (type
);
4009 else if (wi_zero_p (type
, lh_lb
, lh_ub
) && wi_zero_p (type
, rh_lb
, rh_ub
))
4010 r
= range_zero (type
);
4012 r
.set_varying (type
);
4016 class pointer_and_operator
: public range_operator
4019 virtual void wi_fold (irange
&r
, tree type
,
4020 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
4021 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const;
4025 pointer_and_operator::wi_fold (irange
&r
, tree type
,
4026 const wide_int
&lh_lb
,
4027 const wide_int
&lh_ub
,
4028 const wide_int
&rh_lb ATTRIBUTE_UNUSED
,
4029 const wide_int
&rh_ub ATTRIBUTE_UNUSED
) const
4031 // For pointer types, we are really only interested in asserting
4032 // whether the expression evaluates to non-NULL.
4033 if (wi_zero_p (type
, lh_lb
, lh_ub
) || wi_zero_p (type
, lh_lb
, lh_ub
))
4034 r
= range_zero (type
);
4036 r
.set_varying (type
);
4040 class pointer_or_operator
: public range_operator
4042 using range_operator::op1_range
;
4043 using range_operator::op2_range
;
4045 virtual bool op1_range (irange
&r
, tree type
,
4048 relation_kind rel
= VREL_VARYING
) const;
4049 virtual bool op2_range (irange
&r
, tree type
,
4052 relation_kind rel
= VREL_VARYING
) const;
4053 virtual void wi_fold (irange
&r
, tree type
,
4054 const wide_int
&lh_lb
, const wide_int
&lh_ub
,
4055 const wide_int
&rh_lb
, const wide_int
&rh_ub
) const;
4059 pointer_or_operator::op1_range (irange
&r
, tree type
,
4061 const irange
&op2 ATTRIBUTE_UNUSED
,
4062 relation_kind rel ATTRIBUTE_UNUSED
) const
4066 tree zero
= build_zero_cst (type
);
4067 r
= int_range
<1> (zero
, zero
);
4070 r
.set_varying (type
);
4075 pointer_or_operator::op2_range (irange
&r
, tree type
,
4078 relation_kind rel ATTRIBUTE_UNUSED
) const
4080 return pointer_or_operator::op1_range (r
, type
, lhs
, op1
);
4084 pointer_or_operator::wi_fold (irange
&r
, tree type
,
4085 const wide_int
&lh_lb
,
4086 const wide_int
&lh_ub
,
4087 const wide_int
&rh_lb
,
4088 const wide_int
&rh_ub
) const
4090 // For pointer types, we are really only interested in asserting
4091 // whether the expression evaluates to non-NULL.
4092 if (!wi_includes_zero_p (type
, lh_lb
, lh_ub
)
4093 && !wi_includes_zero_p (type
, rh_lb
, rh_ub
))
4094 r
= range_nonzero (type
);
4095 else if (wi_zero_p (type
, lh_lb
, lh_ub
) && wi_zero_p (type
, rh_lb
, rh_ub
))
4096 r
= range_zero (type
);
4098 r
.set_varying (type
);
4101 // Return a pointer to the range_operator instance, if there is one
4102 // associated with tree_code CODE.
4105 range_op_table::operator[] (enum tree_code code
)
4107 gcc_checking_assert (code
> 0 && code
< MAX_TREE_CODES
);
4108 return m_range_tree
[code
];
4111 // Add OP to the handler table for CODE.
4114 range_op_table::set (enum tree_code code
, range_operator
&op
)
4116 gcc_checking_assert (m_range_tree
[code
] == NULL
);
4117 m_range_tree
[code
] = &op
;
4120 // Instantiate a range op table for integral operations.
4122 class integral_table
: public range_op_table
4126 } integral_tree_table
;
4128 integral_table::integral_table ()
4130 set (EQ_EXPR
, op_equal
);
4131 set (NE_EXPR
, op_not_equal
);
4132 set (LT_EXPR
, op_lt
);
4133 set (LE_EXPR
, op_le
);
4134 set (GT_EXPR
, op_gt
);
4135 set (GE_EXPR
, op_ge
);
4136 set (PLUS_EXPR
, op_plus
);
4137 set (MINUS_EXPR
, op_minus
);
4138 set (MIN_EXPR
, op_min
);
4139 set (MAX_EXPR
, op_max
);
4140 set (MULT_EXPR
, op_mult
);
4141 set (TRUNC_DIV_EXPR
, op_trunc_div
);
4142 set (FLOOR_DIV_EXPR
, op_floor_div
);
4143 set (ROUND_DIV_EXPR
, op_round_div
);
4144 set (CEIL_DIV_EXPR
, op_ceil_div
);
4145 set (EXACT_DIV_EXPR
, op_exact_div
);
4146 set (LSHIFT_EXPR
, op_lshift
);
4147 set (RSHIFT_EXPR
, op_rshift
);
4148 set (NOP_EXPR
, op_convert
);
4149 set (CONVERT_EXPR
, op_convert
);
4150 set (TRUTH_AND_EXPR
, op_logical_and
);
4151 set (BIT_AND_EXPR
, op_bitwise_and
);
4152 set (TRUTH_OR_EXPR
, op_logical_or
);
4153 set (BIT_IOR_EXPR
, op_bitwise_or
);
4154 set (BIT_XOR_EXPR
, op_bitwise_xor
);
4155 set (TRUNC_MOD_EXPR
, op_trunc_mod
);
4156 set (TRUTH_NOT_EXPR
, op_logical_not
);
4157 set (BIT_NOT_EXPR
, op_bitwise_not
);
4158 set (INTEGER_CST
, op_integer_cst
);
4159 set (SSA_NAME
, op_identity
);
4160 set (PAREN_EXPR
, op_identity
);
4161 set (OBJ_TYPE_REF
, op_identity
);
4162 set (IMAGPART_EXPR
, op_unknown
);
4163 set (REALPART_EXPR
, op_unknown
);
4164 set (POINTER_DIFF_EXPR
, op_pointer_diff
);
4165 set (ABS_EXPR
, op_abs
);
4166 set (ABSU_EXPR
, op_absu
);
4167 set (NEGATE_EXPR
, op_negate
);
4168 set (ADDR_EXPR
, op_addr
);
4171 // Instantiate a range op table for pointer operations.
4173 class pointer_table
: public range_op_table
4177 } pointer_tree_table
;
4179 pointer_table::pointer_table ()
4181 set (BIT_AND_EXPR
, op_pointer_and
);
4182 set (BIT_IOR_EXPR
, op_pointer_or
);
4183 set (MIN_EXPR
, op_ptr_min_max
);
4184 set (MAX_EXPR
, op_ptr_min_max
);
4185 set (POINTER_PLUS_EXPR
, op_pointer_plus
);
4187 set (EQ_EXPR
, op_equal
);
4188 set (NE_EXPR
, op_not_equal
);
4189 set (LT_EXPR
, op_lt
);
4190 set (LE_EXPR
, op_le
);
4191 set (GT_EXPR
, op_gt
);
4192 set (GE_EXPR
, op_ge
);
4193 set (SSA_NAME
, op_identity
);
4194 set (INTEGER_CST
, op_integer_cst
);
4195 set (ADDR_EXPR
, op_addr
);
4196 set (NOP_EXPR
, op_convert
);
4197 set (CONVERT_EXPR
, op_convert
);
4199 set (BIT_NOT_EXPR
, op_bitwise_not
);
4200 set (BIT_XOR_EXPR
, op_bitwise_xor
);
4203 // The tables are hidden and accessed via a simple extern function.
4205 static inline range_operator
*
4206 get_handler (enum tree_code code
, tree type
)
4208 // First check if there is a pointer specialization.
4209 if (POINTER_TYPE_P (type
))
4210 return pointer_tree_table
[code
];
4211 if (INTEGRAL_TYPE_P (type
))
4212 return integral_tree_table
[code
];
4216 range_op_handler::range_op_handler (tree_code code
, tree type
)
4218 m_op
= get_handler (code
, type
);
4221 range_op_handler::range_op_handler (const gimple
*s
)
4223 if (const gassign
*ass
= dyn_cast
<const gassign
*> (s
))
4225 enum tree_code code
= gimple_assign_rhs_code (ass
);
4226 // The LHS of a comparison is always an int, so we must look at
4228 if (TREE_CODE_CLASS (code
) == tcc_comparison
)
4229 m_op
= get_handler (code
, TREE_TYPE (gimple_assign_rhs1 (ass
)));
4231 m_op
= get_handler (code
, TREE_TYPE (gimple_assign_lhs (ass
)));
4233 else if (const gcond
*cond
= dyn_cast
<const gcond
*> (s
))
4234 m_op
= get_handler (gimple_cond_code (cond
),
4235 TREE_TYPE (gimple_cond_lhs (cond
)));
4241 range_op_handler::fold_range (vrange
&r
, tree type
,
4244 relation_kind rel
) const
4246 if (is_a
<irange
> (lh
))
4247 return m_op
->fold_range (as_a
<irange
> (r
), type
,
4249 as_a
<irange
> (rh
), rel
);
4255 range_op_handler::op1_range (vrange
&r
, tree type
,
4258 relation_kind rel
) const
4260 if (is_a
<irange
> (r
))
4261 return m_op
->op1_range (as_a
<irange
> (r
), type
,
4262 as_a
<irange
> (lhs
),
4263 as_a
<irange
> (op2
), rel
);
4269 range_op_handler::op2_range (vrange
&r
, tree type
,
4272 relation_kind rel
) const
4274 if (is_a
<irange
> (r
))
4275 return m_op
->op2_range (as_a
<irange
> (r
), type
,
4276 as_a
<irange
> (lhs
),
4277 as_a
<irange
> (op1
), rel
);
4283 range_op_handler::lhs_op1_relation (const vrange
&lhs
,
4286 relation_kind rel
) const
4288 if (is_a
<irange
> (op1
))
4289 return m_op
->lhs_op1_relation (as_a
<irange
> (lhs
),
4290 as_a
<irange
> (op1
), as_a
<irange
> (op2
), rel
);
4292 return VREL_VARYING
;
4296 range_op_handler::lhs_op2_relation (const vrange
&lhs
,
4299 relation_kind rel
) const
4301 if (is_a
<irange
> (op1
))
4302 return m_op
->lhs_op2_relation (as_a
<irange
> (lhs
),
4303 as_a
<irange
> (op1
), as_a
<irange
> (op2
), rel
);
4305 return VREL_VARYING
;
4309 range_op_handler::op1_op2_relation (const vrange
&lhs
) const
4311 return m_op
->op1_op2_relation (as_a
<irange
> (lhs
));
4314 // Cast the range in R to TYPE.
4317 range_cast (vrange
&r
, tree type
)
4319 Value_Range
tmp (r
);
4320 Value_Range
varying (type
);
4321 varying
.set_varying (type
);
4322 range_op_handler
op (CONVERT_EXPR
, type
);
4323 // Call op_convert, if it fails, the result is varying.
4324 if (!op
|| !op
.fold_range (r
, type
, tmp
, varying
))
4326 r
.set_varying (type
);
4333 #include "selftest.h"
4337 #define INT(N) build_int_cst (integer_type_node, (N))
4338 #define UINT(N) build_int_cstu (unsigned_type_node, (N))
4339 #define INT16(N) build_int_cst (short_integer_type_node, (N))
4340 #define UINT16(N) build_int_cstu (short_unsigned_type_node, (N))
4341 #define SCHAR(N) build_int_cst (signed_char_type_node, (N))
4342 #define UCHAR(N) build_int_cstu (unsigned_char_type_node, (N))
4345 range_op_cast_tests ()
4347 int_range
<1> r0
, r1
, r2
, rold
;
4348 r0
.set_varying (integer_type_node
);
4349 tree maxint
= wide_int_to_tree (integer_type_node
, r0
.upper_bound ());
4351 // If a range is in any way outside of the range for the converted
4352 // to range, default to the range for the new type.
4353 r0
.set_varying (short_integer_type_node
);
4354 tree minshort
= wide_int_to_tree (short_integer_type_node
, r0
.lower_bound ());
4355 tree maxshort
= wide_int_to_tree (short_integer_type_node
, r0
.upper_bound ());
4356 if (TYPE_PRECISION (TREE_TYPE (maxint
))
4357 > TYPE_PRECISION (short_integer_type_node
))
4359 r1
= int_range
<1> (integer_zero_node
, maxint
);
4360 range_cast (r1
, short_integer_type_node
);
4361 ASSERT_TRUE (r1
.lower_bound () == wi::to_wide (minshort
)
4362 && r1
.upper_bound() == wi::to_wide (maxshort
));
4365 // (unsigned char)[-5,-1] => [251,255].
4366 r0
= rold
= int_range
<1> (SCHAR (-5), SCHAR (-1));
4367 range_cast (r0
, unsigned_char_type_node
);
4368 ASSERT_TRUE (r0
== int_range
<1> (UCHAR (251), UCHAR (255)));
4369 range_cast (r0
, signed_char_type_node
);
4370 ASSERT_TRUE (r0
== rold
);
4372 // (signed char)[15, 150] => [-128,-106][15,127].
4373 r0
= rold
= int_range
<1> (UCHAR (15), UCHAR (150));
4374 range_cast (r0
, signed_char_type_node
);
4375 r1
= int_range
<1> (SCHAR (15), SCHAR (127));
4376 r2
= int_range
<1> (SCHAR (-128), SCHAR (-106));
4378 ASSERT_TRUE (r1
== r0
);
4379 range_cast (r0
, unsigned_char_type_node
);
4380 ASSERT_TRUE (r0
== rold
);
4382 // (unsigned char)[-5, 5] => [0,5][251,255].
4383 r0
= rold
= int_range
<1> (SCHAR (-5), SCHAR (5));
4384 range_cast (r0
, unsigned_char_type_node
);
4385 r1
= int_range
<1> (UCHAR (251), UCHAR (255));
4386 r2
= int_range
<1> (UCHAR (0), UCHAR (5));
4388 ASSERT_TRUE (r0
== r1
);
4389 range_cast (r0
, signed_char_type_node
);
4390 ASSERT_TRUE (r0
== rold
);
4392 // (unsigned char)[-5,5] => [0,5][251,255].
4393 r0
= int_range
<1> (INT (-5), INT (5));
4394 range_cast (r0
, unsigned_char_type_node
);
4395 r1
= int_range
<1> (UCHAR (0), UCHAR (5));
4396 r1
.union_ (int_range
<1> (UCHAR (251), UCHAR (255)));
4397 ASSERT_TRUE (r0
== r1
);
4399 // (unsigned char)[5U,1974U] => [0,255].
4400 r0
= int_range
<1> (UINT (5), UINT (1974));
4401 range_cast (r0
, unsigned_char_type_node
);
4402 ASSERT_TRUE (r0
== int_range
<1> (UCHAR (0), UCHAR (255)));
4403 range_cast (r0
, integer_type_node
);
4404 // Going to a wider range should not sign extend.
4405 ASSERT_TRUE (r0
== int_range
<1> (INT (0), INT (255)));
4407 // (unsigned char)[-350,15] => [0,255].
4408 r0
= int_range
<1> (INT (-350), INT (15));
4409 range_cast (r0
, unsigned_char_type_node
);
4410 ASSERT_TRUE (r0
== (int_range
<1>
4411 (TYPE_MIN_VALUE (unsigned_char_type_node
),
4412 TYPE_MAX_VALUE (unsigned_char_type_node
))));
4414 // Casting [-120,20] from signed char to unsigned short.
4415 // => [0, 20][0xff88, 0xffff].
4416 r0
= int_range
<1> (SCHAR (-120), SCHAR (20));
4417 range_cast (r0
, short_unsigned_type_node
);
4418 r1
= int_range
<1> (UINT16 (0), UINT16 (20));
4419 r2
= int_range
<1> (UINT16 (0xff88), UINT16 (0xffff));
4421 ASSERT_TRUE (r0
== r1
);
4422 // A truncating cast back to signed char will work because [-120, 20]
4423 // is representable in signed char.
4424 range_cast (r0
, signed_char_type_node
);
4425 ASSERT_TRUE (r0
== int_range
<1> (SCHAR (-120), SCHAR (20)));
4427 // unsigned char -> signed short
4428 // (signed short)[(unsigned char)25, (unsigned char)250]
4429 // => [(signed short)25, (signed short)250]
4430 r0
= rold
= int_range
<1> (UCHAR (25), UCHAR (250));
4431 range_cast (r0
, short_integer_type_node
);
4432 r1
= int_range
<1> (INT16 (25), INT16 (250));
4433 ASSERT_TRUE (r0
== r1
);
4434 range_cast (r0
, unsigned_char_type_node
);
4435 ASSERT_TRUE (r0
== rold
);
4437 // Test casting a wider signed [-MIN,MAX] to a nar`rower unsigned.
4438 r0
= int_range
<1> (TYPE_MIN_VALUE (long_long_integer_type_node
),
4439 TYPE_MAX_VALUE (long_long_integer_type_node
));
4440 range_cast (r0
, short_unsigned_type_node
);
4441 r1
= int_range
<1> (TYPE_MIN_VALUE (short_unsigned_type_node
),
4442 TYPE_MAX_VALUE (short_unsigned_type_node
));
4443 ASSERT_TRUE (r0
== r1
);
4445 // Casting NONZERO to a narrower type will wrap/overflow so
4446 // it's just the entire range for the narrower type.
4448 // "NOT 0 at signed 32-bits" ==> [-MIN_32,-1][1, +MAX_32]. This is
4449 // is outside of the range of a smaller range, return the full
4451 if (TYPE_PRECISION (integer_type_node
)
4452 > TYPE_PRECISION (short_integer_type_node
))
4454 r0
= range_nonzero (integer_type_node
);
4455 range_cast (r0
, short_integer_type_node
);
4456 r1
= int_range
<1> (TYPE_MIN_VALUE (short_integer_type_node
),
4457 TYPE_MAX_VALUE (short_integer_type_node
));
4458 ASSERT_TRUE (r0
== r1
);
4461 // Casting NONZERO from a narrower signed to a wider signed.
4463 // NONZERO signed 16-bits is [-MIN_16,-1][1, +MAX_16].
4464 // Converting this to 32-bits signed is [-MIN_16,-1][1, +MAX_16].
4465 r0
= range_nonzero (short_integer_type_node
);
4466 range_cast (r0
, integer_type_node
);
4467 r1
= int_range
<1> (INT (-32768), INT (-1));
4468 r2
= int_range
<1> (INT (1), INT (32767));
4470 ASSERT_TRUE (r0
== r1
);
4474 range_op_lshift_tests ()
4476 // Test that 0x808.... & 0x8.... still contains 0x8....
4477 // for a large set of numbers.
4480 tree big_type
= long_long_unsigned_type_node
;
4481 // big_num = 0x808,0000,0000,0000
4482 tree big_num
= fold_build2 (LSHIFT_EXPR
, big_type
,
4483 build_int_cst (big_type
, 0x808),
4484 build_int_cst (big_type
, 48));
4485 op_bitwise_and
.fold_range (res
, big_type
,
4486 int_range
<1> (big_type
),
4487 int_range
<1> (big_num
, big_num
));
4488 // val = 0x8,0000,0000,0000
4489 tree val
= fold_build2 (LSHIFT_EXPR
, big_type
,
4490 build_int_cst (big_type
, 0x8),
4491 build_int_cst (big_type
, 48));
4492 ASSERT_TRUE (res
.contains_p (val
));
4495 if (TYPE_PRECISION (unsigned_type_node
) > 31)
4497 // unsigned VARYING = op1 << 1 should be VARYING.
4498 int_range
<2> lhs (unsigned_type_node
);
4499 int_range
<2> shift (INT (1), INT (1));
4501 op_lshift
.op1_range (op1
, unsigned_type_node
, lhs
, shift
);
4502 ASSERT_TRUE (op1
.varying_p ());
4504 // 0 = op1 << 1 should be [0,0], [0x8000000, 0x8000000].
4505 int_range
<2> zero (UINT (0), UINT (0));
4506 op_lshift
.op1_range (op1
, unsigned_type_node
, zero
, shift
);
4507 ASSERT_TRUE (op1
.num_pairs () == 2);
4508 // Remove the [0,0] range.
4509 op1
.intersect (zero
);
4510 ASSERT_TRUE (op1
.num_pairs () == 1);
4511 // op1 << 1 should be [0x8000,0x8000] << 1,
4512 // which should result in [0,0].
4513 int_range_max result
;
4514 op_lshift
.fold_range (result
, unsigned_type_node
, op1
, shift
);
4515 ASSERT_TRUE (result
== zero
);
4517 // signed VARYING = op1 << 1 should be VARYING.
4518 if (TYPE_PRECISION (integer_type_node
) > 31)
4520 // unsigned VARYING = op1 << 1 hould be VARYING.
4521 int_range
<2> lhs (integer_type_node
);
4522 int_range
<2> shift (INT (1), INT (1));
4524 op_lshift
.op1_range (op1
, integer_type_node
, lhs
, shift
);
4525 ASSERT_TRUE (op1
.varying_p ());
4527 // 0 = op1 << 1 should be [0,0], [0x8000000, 0x8000000].
4528 int_range
<2> zero (INT (0), INT (0));
4529 op_lshift
.op1_range (op1
, integer_type_node
, zero
, shift
);
4530 ASSERT_TRUE (op1
.num_pairs () == 2);
4531 // Remove the [0,0] range.
4532 op1
.intersect (zero
);
4533 ASSERT_TRUE (op1
.num_pairs () == 1);
4534 // op1 << 1 shuould be [0x8000,0x8000] << 1,
4535 // which should result in [0,0].
4536 int_range_max result
;
4537 op_lshift
.fold_range (result
, unsigned_type_node
, op1
, shift
);
4538 ASSERT_TRUE (result
== zero
);
4543 range_op_rshift_tests ()
4545 // unsigned: [3, MAX] = OP1 >> 1
4547 int_range_max
lhs (build_int_cst (unsigned_type_node
, 3),
4548 TYPE_MAX_VALUE (unsigned_type_node
));
4549 int_range_max
one (build_one_cst (unsigned_type_node
),
4550 build_one_cst (unsigned_type_node
));
4552 op_rshift
.op1_range (op1
, unsigned_type_node
, lhs
, one
);
4553 ASSERT_FALSE (op1
.contains_p (UINT (3)));
4556 // signed: [3, MAX] = OP1 >> 1
4558 int_range_max
lhs (INT (3), TYPE_MAX_VALUE (integer_type_node
));
4559 int_range_max
one (INT (1), INT (1));
4561 op_rshift
.op1_range (op1
, integer_type_node
, lhs
, one
);
4562 ASSERT_FALSE (op1
.contains_p (INT (-2)));
4565 // This is impossible, so OP1 should be [].
4566 // signed: [MIN, MIN] = OP1 >> 1
4568 int_range_max
lhs (TYPE_MIN_VALUE (integer_type_node
),
4569 TYPE_MIN_VALUE (integer_type_node
));
4570 int_range_max
one (INT (1), INT (1));
4572 op_rshift
.op1_range (op1
, integer_type_node
, lhs
, one
);
4573 ASSERT_TRUE (op1
.undefined_p ());
4576 // signed: ~[-1] = OP1 >> 31
4577 if (TYPE_PRECISION (integer_type_node
) > 31)
4579 int_range_max
lhs (INT (-1), INT (-1), VR_ANTI_RANGE
);
4580 int_range_max
shift (INT (31), INT (31));
4582 op_rshift
.op1_range (op1
, integer_type_node
, lhs
, shift
);
4583 int_range_max negatives
= range_negatives (integer_type_node
);
4584 negatives
.intersect (op1
);
4585 ASSERT_TRUE (negatives
.undefined_p ());
4590 range_op_bitwise_and_tests ()
4593 tree min
= vrp_val_min (integer_type_node
);
4594 tree max
= vrp_val_max (integer_type_node
);
4595 tree tiny
= fold_build2 (PLUS_EXPR
, integer_type_node
, min
,
4596 build_one_cst (integer_type_node
));
4597 int_range_max
i1 (tiny
, max
);
4598 int_range_max
i2 (build_int_cst (integer_type_node
, 255),
4599 build_int_cst (integer_type_node
, 255));
4601 // [MIN+1, MAX] = OP1 & 255: OP1 is VARYING
4602 op_bitwise_and
.op1_range (res
, integer_type_node
, i1
, i2
);
4603 ASSERT_TRUE (res
== int_range
<1> (integer_type_node
));
4605 // VARYING = OP1 & 255: OP1 is VARYING
4606 i1
= int_range
<1> (integer_type_node
);
4607 op_bitwise_and
.op1_range (res
, integer_type_node
, i1
, i2
);
4608 ASSERT_TRUE (res
== int_range
<1> (integer_type_node
));
4610 // (NONZERO | X) is nonzero.
4611 i1
.set_nonzero (integer_type_node
);
4612 i2
.set_varying (integer_type_node
);
4613 op_bitwise_or
.fold_range (res
, integer_type_node
, i1
, i2
);
4614 ASSERT_TRUE (res
.nonzero_p ());
4616 // (NEGATIVE | X) is nonzero.
4617 i1
= int_range
<1> (INT (-5), INT (-3));
4618 i2
.set_varying (integer_type_node
);
4619 op_bitwise_or
.fold_range (res
, integer_type_node
, i1
, i2
);
4620 ASSERT_FALSE (res
.contains_p (INT (0)));
4624 range_relational_tests ()
4626 int_range
<2> lhs (unsigned_char_type_node
);
4627 int_range
<2> op1 (UCHAR (8), UCHAR (10));
4628 int_range
<2> op2 (UCHAR (20), UCHAR (20));
4630 // Never wrapping additions mean LHS > OP1.
4631 relation_kind code
= op_plus
.lhs_op1_relation (lhs
, op1
, op2
, VREL_VARYING
);
4632 ASSERT_TRUE (code
== VREL_GT
);
4634 // Most wrapping additions mean nothing...
4635 op1
= int_range
<2> (UCHAR (8), UCHAR (10));
4636 op2
= int_range
<2> (UCHAR (0), UCHAR (255));
4637 code
= op_plus
.lhs_op1_relation (lhs
, op1
, op2
, VREL_VARYING
);
4638 ASSERT_TRUE (code
== VREL_VARYING
);
4640 // However, always wrapping additions mean LHS < OP1.
4641 op1
= int_range
<2> (UCHAR (1), UCHAR (255));
4642 op2
= int_range
<2> (UCHAR (255), UCHAR (255));
4643 code
= op_plus
.lhs_op1_relation (lhs
, op1
, op2
, VREL_VARYING
);
4644 ASSERT_TRUE (code
== VREL_LT
);
4650 range_op_rshift_tests ();
4651 range_op_lshift_tests ();
4652 range_op_bitwise_and_tests ();
4653 range_op_cast_tests ();
4654 range_relational_tests ();
4657 } // namespace selftest
4659 #endif // CHECKING_P