c++: fix cxx_print_type's template-info dumping
[official-gcc.git] / gcc / range-op-float.cc
blob5eb1d9c06e3c4c68aeeeeb20d8695ad7c1a405bd
1 /* Floating point range operators.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "insn-codes.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "gimple.h"
29 #include "cfghooks.h"
30 #include "tree-pass.h"
31 #include "ssa.h"
32 #include "optabs-tree.h"
33 #include "gimple-pretty-print.h"
34 #include "diagnostic-core.h"
35 #include "flags.h"
36 #include "fold-const.h"
37 #include "stor-layout.h"
38 #include "calls.h"
39 #include "cfganal.h"
40 #include "gimple-iterator.h"
41 #include "gimple-fold.h"
42 #include "tree-eh.h"
43 #include "gimple-walk.h"
44 #include "tree-cfg.h"
45 #include "wide-int.h"
46 #include "value-relation.h"
47 #include "range-op.h"
48 #include "range-op-mixed.h"
50 // Default definitions for floating point operators.
52 bool
53 range_operator::fold_range (frange &r, tree type,
54 const frange &op1, const frange &op2,
55 relation_trio trio) const
57 if (empty_range_varying (r, type, op1, op2))
58 return true;
59 if (op1.known_isnan () || op2.known_isnan ())
61 r.set_nan (type);
62 return true;
65 REAL_VALUE_TYPE lb, ub;
66 bool maybe_nan;
67 rv_fold (lb, ub, maybe_nan, type,
68 op1.lower_bound (), op1.upper_bound (),
69 op2.lower_bound (), op2.upper_bound (), trio.op1_op2 ());
71 // Handle possible NANs by saturating to the appropriate INF if only
72 // one end is a NAN. If both ends are a NAN, just return a NAN.
73 bool lb_nan = real_isnan (&lb);
74 bool ub_nan = real_isnan (&ub);
75 if (lb_nan && ub_nan)
77 r.set_nan (type);
78 return true;
80 if (lb_nan)
81 lb = dconstninf;
82 else if (ub_nan)
83 ub = dconstinf;
85 r.set (type, lb, ub);
87 if (lb_nan || ub_nan || maybe_nan
88 || op1.maybe_isnan ()
89 || op2.maybe_isnan ())
90 // Keep the default NAN (with a varying sign) set by the setter.
92 else
93 r.clear_nan ();
95 // If the result has overflowed and flag_trapping_math, folding this
96 // operation could elide an overflow or division by zero exception.
97 // Avoid returning a singleton +-INF, to keep the propagators (DOM
98 // and substitute_and_fold_engine) from folding. See PR107608.
99 if (flag_trapping_math
100 && MODE_HAS_INFINITIES (TYPE_MODE (type))
101 && r.known_isinf () && !op1.known_isinf () && !op2.known_isinf ())
103 REAL_VALUE_TYPE inf = r.lower_bound ();
104 if (real_isneg (&inf))
106 REAL_VALUE_TYPE min = real_min_representable (type);
107 r.set (type, inf, min);
109 else
111 REAL_VALUE_TYPE max = real_max_representable (type);
112 r.set (type, max, inf);
116 r.flush_denormals_to_zero ();
118 return true;
121 // For a given operation, fold two sets of ranges into [lb, ub].
122 // MAYBE_NAN is set to TRUE if, in addition to any result in LB or
123 // UB, the final range has the possibility of a NAN.
124 void
125 range_operator::rv_fold (REAL_VALUE_TYPE &lb,
126 REAL_VALUE_TYPE &ub,
127 bool &maybe_nan,
128 tree type ATTRIBUTE_UNUSED,
129 const REAL_VALUE_TYPE &lh_lb ATTRIBUTE_UNUSED,
130 const REAL_VALUE_TYPE &lh_ub ATTRIBUTE_UNUSED,
131 const REAL_VALUE_TYPE &rh_lb ATTRIBUTE_UNUSED,
132 const REAL_VALUE_TYPE &rh_ub ATTRIBUTE_UNUSED,
133 relation_kind) const
135 lb = dconstninf;
136 ub = dconstinf;
137 maybe_nan = true;
140 bool
141 range_operator::fold_range (irange &r ATTRIBUTE_UNUSED,
142 tree type ATTRIBUTE_UNUSED,
143 const frange &lh ATTRIBUTE_UNUSED,
144 const irange &rh ATTRIBUTE_UNUSED,
145 relation_trio) const
147 return false;
150 bool
151 range_operator::fold_range (irange &r ATTRIBUTE_UNUSED,
152 tree type ATTRIBUTE_UNUSED,
153 const frange &lh ATTRIBUTE_UNUSED,
154 const frange &rh ATTRIBUTE_UNUSED,
155 relation_trio) const
157 return false;
160 bool
161 range_operator::fold_range (frange &r ATTRIBUTE_UNUSED,
162 tree type ATTRIBUTE_UNUSED,
163 const irange &lh ATTRIBUTE_UNUSED,
164 const irange &rh ATTRIBUTE_UNUSED,
165 relation_trio) const
167 return false;
170 bool
171 range_operator::op1_range (frange &r ATTRIBUTE_UNUSED,
172 tree type ATTRIBUTE_UNUSED,
173 const frange &lhs ATTRIBUTE_UNUSED,
174 const frange &op2 ATTRIBUTE_UNUSED,
175 relation_trio) const
177 return false;
180 bool
181 range_operator::op1_range (frange &r ATTRIBUTE_UNUSED,
182 tree type ATTRIBUTE_UNUSED,
183 const irange &lhs ATTRIBUTE_UNUSED,
184 const frange &op2 ATTRIBUTE_UNUSED,
185 relation_trio) const
187 return false;
190 bool
191 range_operator::op2_range (frange &r ATTRIBUTE_UNUSED,
192 tree type ATTRIBUTE_UNUSED,
193 const frange &lhs ATTRIBUTE_UNUSED,
194 const frange &op1 ATTRIBUTE_UNUSED,
195 relation_trio) const
197 return false;
200 bool
201 range_operator::op2_range (frange &r ATTRIBUTE_UNUSED,
202 tree type ATTRIBUTE_UNUSED,
203 const irange &lhs ATTRIBUTE_UNUSED,
204 const frange &op1 ATTRIBUTE_UNUSED,
205 relation_trio) const
207 return false;
210 relation_kind
211 range_operator::lhs_op1_relation (const frange &lhs ATTRIBUTE_UNUSED,
212 const frange &op1 ATTRIBUTE_UNUSED,
213 const frange &op2 ATTRIBUTE_UNUSED,
214 relation_kind) const
216 return VREL_VARYING;
219 relation_kind
220 range_operator::lhs_op1_relation (const irange &lhs ATTRIBUTE_UNUSED,
221 const frange &op1 ATTRIBUTE_UNUSED,
222 const frange &op2 ATTRIBUTE_UNUSED,
223 relation_kind) const
225 return VREL_VARYING;
228 relation_kind
229 range_operator::lhs_op2_relation (const irange &lhs ATTRIBUTE_UNUSED,
230 const frange &op1 ATTRIBUTE_UNUSED,
231 const frange &op2 ATTRIBUTE_UNUSED,
232 relation_kind) const
234 return VREL_VARYING;
237 relation_kind
238 range_operator::lhs_op2_relation (const frange &lhs ATTRIBUTE_UNUSED,
239 const frange &op1 ATTRIBUTE_UNUSED,
240 const frange &op2 ATTRIBUTE_UNUSED,
241 relation_kind) const
243 return VREL_VARYING;
246 relation_kind
247 range_operator::op1_op2_relation (const irange &,
248 const frange &,
249 const frange &) const
251 return VREL_VARYING;
255 relation_kind
256 range_operator::op1_op2_relation (const frange &,
257 const frange &,
258 const frange &) const
260 return VREL_VARYING;
263 // Return TRUE if OP1 and OP2 may be a NAN.
265 static inline bool
266 maybe_isnan (const frange &op1, const frange &op2)
268 return op1.maybe_isnan () || op2.maybe_isnan ();
271 // Floating point version of relop_early_resolve that takes NANs into
272 // account.
274 // For relation opcodes, first try to see if the supplied relation
275 // forces a true or false result, and return that.
276 // Then check for undefined operands. If none of this applies,
277 // return false.
279 // TRIO are the relations between operands as they appear in the IL.
280 // MY_REL is the relation that corresponds to the operator being
281 // folded. For example, when attempting to fold x_3 == y_5, MY_REL is
282 // VREL_EQ, and if the statement is dominated by x_3 > y_5, then
283 // TRIO.op1_op2() is VREL_GT.
285 // Relations in a floating point world are a bit tricky, as TRIO
286 // behaves as the corresponding unordered variant if either operand
287 // could be a NAN. For example, when resolving "if (x_5 == x_5)", the
288 // relation is VREL_EQ, but it behaves like VREL_UNEQ if NANs are a
289 // possibility. Similarly, the false edge of "if (x >= y)" has a
290 // relation of VREL_LT, but behaves as VREL_UNLT unless we can prove
291 // neither operand can be NAN.
293 // ?? It is unclear whether providing unordered VREL relations would
294 // simplify things, as we'd have to add more entries to various
295 // tables, tweak all the op1_op2_relation() entries, etc.
297 static inline bool
298 frelop_early_resolve (irange &r, tree type,
299 const frange &op1, const frange &op2,
300 relation_trio trio, relation_kind my_rel)
302 relation_kind rel = trio.op1_op2 ();
304 if (maybe_isnan (op1, op2))
306 // There's not much we can do for VREL_EQ if NAN is a
307 // possibility. It is up to the caller to deal with these
308 // special cases.
309 if (rel == VREL_EQ)
310 return empty_range_varying (r, type, op1, op2);
312 // If known relation is a complete subset of this relation, always
313 // return true. However, avoid doing this when NAN is a possibility
314 // as we'll incorrectly fold conditions:
316 // if (x_3 >= y_5)
317 // ;
318 // else
319 // ;; With NANs the relation here is basically VREL_UNLT, so we
320 // ;; can't fold the following:
321 // if (x_3 < y_5)
322 else if (relation_union (rel, my_rel) == my_rel)
324 r = range_true (type);
325 return true;
328 // If known relation has no subset of this relation, always false.
329 if (relation_intersect (rel, my_rel) == VREL_UNDEFINED)
331 r = range_false (type);
332 return true;
335 // If either operand is undefined, return VARYING.
336 if (empty_range_varying (r, type, op1, op2))
337 return true;
339 return false;
342 // Set VALUE to its next real value, or INF if the operation overflows.
344 void
345 frange_nextafter (enum machine_mode mode,
346 REAL_VALUE_TYPE &value,
347 const REAL_VALUE_TYPE &inf)
349 if (MODE_COMPOSITE_P (mode)
350 && (real_isdenormal (&value, mode) || real_iszero (&value)))
352 // IBM extended denormals only have DFmode precision.
353 REAL_VALUE_TYPE tmp, tmp2;
354 real_convert (&tmp2, DFmode, &value);
355 real_nextafter (&tmp, REAL_MODE_FORMAT (DFmode), &tmp2, &inf);
356 real_convert (&value, mode, &tmp);
358 else
360 REAL_VALUE_TYPE tmp;
361 real_nextafter (&tmp, REAL_MODE_FORMAT (mode), &value, &inf);
362 value = tmp;
366 // Like real_arithmetic, but round the result to INF if the operation
367 // produced inexact results.
369 // ?? There is still one problematic case, i387. With
370 // -fexcess-precision=standard we perform most SF/DFmode arithmetic in
371 // XFmode (long_double_type_node), so that case is OK. But without
372 // -mfpmath=sse, all the SF/DFmode computations are in XFmode
373 // precision (64-bit mantissa) and only occasionally rounded to
374 // SF/DFmode (when storing into memory from the 387 stack). Maybe
375 // this is ok as well though it is just occasionally more precise. ??
377 void
378 frange_arithmetic (enum tree_code code, tree type,
379 REAL_VALUE_TYPE &result,
380 const REAL_VALUE_TYPE &op1,
381 const REAL_VALUE_TYPE &op2,
382 const REAL_VALUE_TYPE &inf)
384 REAL_VALUE_TYPE value;
385 enum machine_mode mode = TYPE_MODE (type);
386 bool mode_composite = MODE_COMPOSITE_P (mode);
388 bool inexact = real_arithmetic (&value, code, &op1, &op2);
389 real_convert (&result, mode, &value);
391 /* When rounding towards negative infinity, x + (-x) and
392 x - x is -0 rather than +0 real_arithmetic computes.
393 So, when we are looking for lower bound (inf is negative),
394 use -0 rather than +0. */
395 if (flag_rounding_math
396 && (code == PLUS_EXPR || code == MINUS_EXPR)
397 && !inexact
398 && real_iszero (&result)
399 && !real_isneg (&result)
400 && real_isneg (&inf))
402 REAL_VALUE_TYPE op2a = op2;
403 if (code == PLUS_EXPR)
404 op2a.sign ^= 1;
405 if (real_isneg (&op1) == real_isneg (&op2a) && real_equal (&op1, &op2a))
406 result.sign = 1;
409 // Be extra careful if there may be discrepancies between the
410 // compile and runtime results.
411 bool round = false;
412 if (mode_composite)
413 round = true;
414 else
416 bool low = real_isneg (&inf);
417 round = (low ? !real_less (&result, &value)
418 : !real_less (&value, &result));
419 if (real_isinf (&result, !low)
420 && !real_isinf (&value)
421 && !flag_rounding_math)
423 // Use just [+INF, +INF] rather than [MAX, +INF]
424 // even if value is larger than MAX and rounds to
425 // nearest to +INF. Similarly just [-INF, -INF]
426 // rather than [-INF, +MAX] even if value is smaller
427 // than -MAX and rounds to nearest to -INF.
428 // Unless INEXACT is true, in that case we need some
429 // extra buffer.
430 if (!inexact)
431 round = false;
432 else
434 REAL_VALUE_TYPE tmp = result, tmp2;
435 frange_nextafter (mode, tmp, inf);
436 // TMP is at this point the maximum representable
437 // number.
438 real_arithmetic (&tmp2, MINUS_EXPR, &value, &tmp);
439 if (real_isneg (&tmp2) != low
440 && (REAL_EXP (&tmp2) - REAL_EXP (&tmp)
441 >= 2 - REAL_MODE_FORMAT (mode)->p))
442 round = false;
446 if (round && (inexact || !real_identical (&result, &value)))
448 if (mode_composite
449 && (real_isdenormal (&result, mode) || real_iszero (&result)))
451 // IBM extended denormals only have DFmode precision.
452 REAL_VALUE_TYPE tmp, tmp2;
453 real_convert (&tmp2, DFmode, &value);
454 real_nextafter (&tmp, REAL_MODE_FORMAT (DFmode), &tmp2, &inf);
455 real_convert (&result, mode, &tmp);
457 else
458 frange_nextafter (mode, result, inf);
460 if (mode_composite)
461 switch (code)
463 case PLUS_EXPR:
464 case MINUS_EXPR:
465 // ibm-ldouble-format documents 1ulp for + and -.
466 frange_nextafter (mode, result, inf);
467 break;
468 case MULT_EXPR:
469 // ibm-ldouble-format documents 2ulps for *.
470 frange_nextafter (mode, result, inf);
471 frange_nextafter (mode, result, inf);
472 break;
473 case RDIV_EXPR:
474 // ibm-ldouble-format documents 3ulps for /.
475 frange_nextafter (mode, result, inf);
476 frange_nextafter (mode, result, inf);
477 frange_nextafter (mode, result, inf);
478 break;
479 default:
480 break;
484 // Crop R to [-INF, MAX] where MAX is the maximum representable number
485 // for TYPE.
487 static inline void
488 frange_drop_inf (frange &r, tree type)
490 REAL_VALUE_TYPE max = real_max_representable (type);
491 frange tmp (type, r.lower_bound (), max);
492 r.intersect (tmp);
495 // Crop R to [MIN, +INF] where MIN is the minimum representable number
496 // for TYPE.
498 static inline void
499 frange_drop_ninf (frange &r, tree type)
501 REAL_VALUE_TYPE min = real_min_representable (type);
502 frange tmp (type, min, r.upper_bound ());
503 r.intersect (tmp);
506 // Crop R to [MIN, MAX] where MAX is the maximum representable number
507 // for TYPE and MIN the minimum representable number for TYPE.
509 static inline void
510 frange_drop_infs (frange &r, tree type)
512 REAL_VALUE_TYPE max = real_max_representable (type);
513 REAL_VALUE_TYPE min = real_min_representable (type);
514 frange tmp (type, min, max);
515 r.intersect (tmp);
518 // If zero is in R, make sure both -0.0 and +0.0 are in the range.
520 static inline void
521 frange_add_zeros (frange &r, tree type)
523 if (r.undefined_p () || r.known_isnan ())
524 return;
526 if (HONOR_SIGNED_ZEROS (type)
527 && (real_iszero (&r.lower_bound ()) || real_iszero (&r.upper_bound ())))
529 frange zero;
530 zero.set_zero (type);
531 r.union_ (zero);
535 // Build a range that is <= VAL and store it in R. Return TRUE if
536 // further changes may be needed for R, or FALSE if R is in its final
537 // form.
539 static bool
540 build_le (frange &r, tree type, const frange &val)
542 gcc_checking_assert (!val.known_isnan ());
544 REAL_VALUE_TYPE ninf = frange_val_min (type);
545 r.set (type, ninf, val.upper_bound ());
547 // Add both zeros if there's the possibility of zero equality.
548 frange_add_zeros (r, type);
550 return true;
553 // Build a range that is < VAL and store it in R. Return TRUE if
554 // further changes may be needed for R, or FALSE if R is in its final
555 // form.
557 static bool
558 build_lt (frange &r, tree type, const frange &val)
560 gcc_checking_assert (!val.known_isnan ());
562 // < -INF is outside the range.
563 if (real_isinf (&val.upper_bound (), 1))
565 if (HONOR_NANS (type))
566 r.set_nan (type);
567 else
568 r.set_undefined ();
569 return false;
572 REAL_VALUE_TYPE ninf = frange_val_min (type);
573 REAL_VALUE_TYPE prev = val.upper_bound ();
574 machine_mode mode = TYPE_MODE (type);
575 // Default to the conservatively correct closed ranges for
576 // MODE_COMPOSITE_P, otherwise use nextafter. Note that for
577 // !HONOR_INFINITIES, nextafter will yield -INF, but frange::set()
578 // will crop the range appropriately.
579 if (!MODE_COMPOSITE_P (mode))
580 frange_nextafter (mode, prev, ninf);
581 r.set (type, ninf, prev);
582 return true;
585 // Build a range that is >= VAL and store it in R. Return TRUE if
586 // further changes may be needed for R, or FALSE if R is in its final
587 // form.
589 static bool
590 build_ge (frange &r, tree type, const frange &val)
592 gcc_checking_assert (!val.known_isnan ());
594 REAL_VALUE_TYPE inf = frange_val_max (type);
595 r.set (type, val.lower_bound (), inf);
597 // Add both zeros if there's the possibility of zero equality.
598 frange_add_zeros (r, type);
600 return true;
603 // Build a range that is > VAL and store it in R. Return TRUE if
604 // further changes may be needed for R, or FALSE if R is in its final
605 // form.
607 static bool
608 build_gt (frange &r, tree type, const frange &val)
610 gcc_checking_assert (!val.known_isnan ());
612 // > +INF is outside the range.
613 if (real_isinf (&val.lower_bound (), 0))
615 if (HONOR_NANS (type))
616 r.set_nan (type);
617 else
618 r.set_undefined ();
619 return false;
622 REAL_VALUE_TYPE inf = frange_val_max (type);
623 REAL_VALUE_TYPE next = val.lower_bound ();
624 machine_mode mode = TYPE_MODE (type);
625 // Default to the conservatively correct closed ranges for
626 // MODE_COMPOSITE_P, otherwise use nextafter. Note that for
627 // !HONOR_INFINITIES, nextafter will yield +INF, but frange::set()
628 // will crop the range appropriately.
629 if (!MODE_COMPOSITE_P (mode))
630 frange_nextafter (mode, next, inf);
631 r.set (type, next, inf);
632 return true;
636 bool
637 operator_identity::fold_range (frange &r, tree, const frange &op1,
638 const frange &, relation_trio) const
640 r = op1;
641 return true;
644 bool
645 operator_identity::op1_range (frange &r, tree, const frange &lhs,
646 const frange &, relation_trio) const
648 r = lhs;
649 return true;
652 bool
653 operator_cst::fold_range (frange &r, tree, const frange &op1,
654 const frange &, relation_trio) const
656 r = op1;
657 return true;
660 bool
661 operator_equal::op2_range (frange &r, tree type,
662 const irange &lhs, const frange &op1,
663 relation_trio rel) const
665 return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
668 bool
669 operator_equal::fold_range (irange &r, tree type,
670 const frange &op1, const frange &op2,
671 relation_trio rel) const
673 if (frelop_early_resolve (r, type, op1, op2, rel, VREL_EQ))
674 return true;
676 if (op1.known_isnan () || op2.known_isnan ())
677 r = range_false (type);
678 // We can be sure the values are always equal or not if both ranges
679 // consist of a single value, and then compare them.
680 else if (op1.singleton_p () && op2.singleton_p ())
682 if (op1 == op2)
683 r = range_true (type);
684 // If one operand is -0.0 and other 0.0, they are still equal.
685 else if (real_iszero (&op1.lower_bound ())
686 && real_iszero (&op2.lower_bound ()))
687 r = range_true (type);
688 else
689 r = range_false (type);
691 else if (real_iszero (&op1.lower_bound ())
692 && real_iszero (&op1.upper_bound ())
693 && real_iszero (&op2.lower_bound ())
694 && real_iszero (&op2.upper_bound ())
695 && !maybe_isnan (op1, op2))
696 // [-0.0, 0.0] == [-0.0, 0.0] or similar.
697 r = range_true (type);
698 else
700 // If ranges do not intersect, we know the range is not equal,
701 // otherwise we don't know anything for sure.
702 frange tmp = op1;
703 tmp.intersect (op2);
704 if (tmp.undefined_p ())
706 // If one range is [whatever, -0.0] and another
707 // [0.0, whatever2], we don't know anything either,
708 // because -0.0 == 0.0.
709 if ((real_iszero (&op1.upper_bound ())
710 && real_iszero (&op2.lower_bound ()))
711 || (real_iszero (&op1.lower_bound ())
712 && real_iszero (&op2.upper_bound ())))
713 r = range_true_and_false (type);
714 else
715 r = range_false (type);
717 else
718 r = range_true_and_false (type);
720 return true;
723 bool
724 operator_equal::op1_range (frange &r, tree type,
725 const irange &lhs,
726 const frange &op2,
727 relation_trio trio) const
729 relation_kind rel = trio.op1_op2 ();
730 switch (get_bool_state (r, lhs, type))
732 case BRS_TRUE:
733 // The TRUE side of x == NAN is unreachable.
734 if (op2.known_isnan ())
735 r.set_undefined ();
736 else
738 // If it's true, the result is the same as OP2.
739 r = op2;
740 // Add both zeros if there's the possibility of zero equality.
741 frange_add_zeros (r, type);
742 // The TRUE side of op1 == op2 implies op1 is !NAN.
743 r.clear_nan ();
745 break;
747 case BRS_FALSE:
748 // The FALSE side of op1 == op1 implies op1 is a NAN.
749 if (rel == VREL_EQ)
750 r.set_nan (type);
751 // On the FALSE side of x == NAN, we know nothing about x.
752 else if (op2.known_isnan ())
753 r.set_varying (type);
754 // If the result is false, the only time we know anything is
755 // if OP2 is a constant.
756 else if (op2.singleton_p ()
757 || (!op2.maybe_isnan () && op2.zero_p ()))
759 REAL_VALUE_TYPE tmp = op2.lower_bound ();
760 r.set (type, tmp, tmp, VR_ANTI_RANGE);
762 else
763 r.set_varying (type);
764 break;
766 default:
767 break;
769 return true;
772 // Check if the LHS range indicates a relation between OP1 and OP2.
774 relation_kind
775 operator_equal::op1_op2_relation (const irange &lhs, const frange &,
776 const frange &) const
778 if (lhs.undefined_p ())
779 return VREL_UNDEFINED;
781 // FALSE = op1 == op2 indicates NE_EXPR.
782 if (lhs.zero_p ())
783 return VREL_NE;
785 // TRUE = op1 == op2 indicates EQ_EXPR.
786 if (!contains_zero_p (lhs))
787 return VREL_EQ;
788 return VREL_VARYING;
791 bool
792 operator_not_equal::fold_range (irange &r, tree type,
793 const frange &op1, const frange &op2,
794 relation_trio trio) const
796 relation_kind rel = trio.op1_op2 ();
798 // VREL_NE & NE_EXPR is always true, even with NANs.
799 if (rel == VREL_NE)
801 r = range_true (type);
802 return true;
804 if (frelop_early_resolve (r, type, op1, op2, trio, VREL_NE))
805 return true;
807 // x != NAN is always TRUE.
808 if (op1.known_isnan () || op2.known_isnan ())
809 r = range_true (type);
810 // We can be sure the values are always equal or not if both ranges
811 // consist of a single value, and then compare them.
812 else if (op1.singleton_p () && op2.singleton_p ())
814 if (op1 == op2)
815 r = range_false (type);
816 // If one operand is -0.0 and other 0.0, they are still equal.
817 else if (real_iszero (&op1.lower_bound ())
818 && real_iszero (&op2.lower_bound ()))
819 r = range_false (type);
820 else
821 r = range_true (type);
823 else if (real_iszero (&op1.lower_bound ())
824 && real_iszero (&op1.upper_bound ())
825 && real_iszero (&op2.lower_bound ())
826 && real_iszero (&op2.upper_bound ())
827 && !maybe_isnan (op1, op2))
828 // [-0.0, 0.0] != [-0.0, 0.0] or similar.
829 r = range_false (type);
830 else
832 // If ranges do not intersect, we know the range is not equal,
833 // otherwise we don't know anything for sure.
834 frange tmp = op1;
835 tmp.intersect (op2);
836 if (tmp.undefined_p ())
838 // If one range is [whatever, -0.0] and another
839 // [0.0, whatever2], we don't know anything either,
840 // because -0.0 == 0.0.
841 if ((real_iszero (&op1.upper_bound ())
842 && real_iszero (&op2.lower_bound ()))
843 || (real_iszero (&op1.lower_bound ())
844 && real_iszero (&op2.upper_bound ())))
845 r = range_true_and_false (type);
846 else
847 r = range_true (type);
849 else
850 r = range_true_and_false (type);
852 return true;
855 bool
856 operator_not_equal::op1_range (frange &r, tree type,
857 const irange &lhs,
858 const frange &op2,
859 relation_trio trio) const
861 relation_kind rel = trio.op1_op2 ();
862 switch (get_bool_state (r, lhs, type))
864 case BRS_TRUE:
865 // If the result is true, the only time we know anything is if
866 // OP2 is a constant.
867 if (op2.singleton_p ())
869 // This is correct even if op1 is NAN, because the following
870 // range would be ~[tmp, tmp] with the NAN property set to
871 // maybe (VARYING).
872 REAL_VALUE_TYPE tmp = op2.lower_bound ();
873 r.set (type, tmp, tmp, VR_ANTI_RANGE);
875 // The TRUE side of op1 != op1 implies op1 is NAN.
876 else if (rel == VREL_EQ)
877 r.set_nan (type);
878 else
879 r.set_varying (type);
880 break;
882 case BRS_FALSE:
883 // The FALSE side of x != NAN is impossible.
884 if (op2.known_isnan ())
885 r.set_undefined ();
886 else
888 // If it's false, the result is the same as OP2.
889 r = op2;
890 // Add both zeros if there's the possibility of zero equality.
891 frange_add_zeros (r, type);
892 // The FALSE side of op1 != op2 implies op1 is !NAN.
893 r.clear_nan ();
895 break;
897 default:
898 break;
900 return true;
903 bool
904 operator_not_equal::op2_range (frange &r, tree type,
905 const irange &lhs,
906 const frange &op1,
907 relation_trio trio) const
909 return op1_range (r, type, lhs, op1, trio);
912 // Check if the LHS range indicates a relation between OP1 and OP2.
914 relation_kind
915 operator_not_equal::op1_op2_relation (const irange &lhs, const frange &,
916 const frange &) const
918 if (lhs.undefined_p ())
919 return VREL_UNDEFINED;
921 // FALSE = op1 != op2 indicates EQ_EXPR.
922 if (lhs.zero_p ())
923 return VREL_EQ;
925 // TRUE = op1 != op2 indicates NE_EXPR.
926 if (!contains_zero_p (lhs))
927 return VREL_NE;
928 return VREL_VARYING;
931 bool
932 operator_lt::fold_range (irange &r, tree type,
933 const frange &op1, const frange &op2,
934 relation_trio trio) const
936 relation_kind rel = trio.op1_op2 ();
938 // VREL_EQ & LT_EXPR is impossible, even with NANs.
939 if (rel == VREL_EQ)
941 r = range_false (type);
942 return true;
944 if (frelop_early_resolve (r, type, op1, op2, trio, VREL_LT))
945 return true;
947 if (op1.known_isnan ()
948 || op2.known_isnan ()
949 || !real_less (&op1.lower_bound (), &op2.upper_bound ()))
950 r = range_false (type);
951 else if (!maybe_isnan (op1, op2)
952 && real_less (&op1.upper_bound (), &op2.lower_bound ()))
953 r = range_true (type);
954 else
955 r = range_true_and_false (type);
956 return true;
959 bool
960 operator_lt::op1_range (frange &r,
961 tree type,
962 const irange &lhs,
963 const frange &op2,
964 relation_trio) const
966 switch (get_bool_state (r, lhs, type))
968 case BRS_TRUE:
969 // The TRUE side of x < NAN is unreachable.
970 if (op2.known_isnan ())
971 r.set_undefined ();
972 else if (op2.undefined_p ())
973 return false;
974 else if (build_lt (r, type, op2))
976 r.clear_nan ();
977 // x < y implies x is not +INF.
978 frange_drop_inf (r, type);
980 break;
982 case BRS_FALSE:
983 // On the FALSE side of x < NAN, we know nothing about x.
984 if (op2.maybe_isnan ())
985 r.set_varying (type);
986 else
987 build_ge (r, type, op2);
988 break;
990 default:
991 break;
993 return true;
996 bool
997 operator_lt::op2_range (frange &r,
998 tree type,
999 const irange &lhs,
1000 const frange &op1,
1001 relation_trio) const
1003 switch (get_bool_state (r, lhs, type))
1005 case BRS_TRUE:
1006 // The TRUE side of NAN < x is unreachable.
1007 if (op1.known_isnan ())
1008 r.set_undefined ();
1009 else if (op1.undefined_p ())
1010 return false;
1011 else if (build_gt (r, type, op1))
1013 r.clear_nan ();
1014 // x < y implies y is not -INF.
1015 frange_drop_ninf (r, type);
1017 break;
1019 case BRS_FALSE:
1020 // On the FALSE side of NAN < x, we know nothing about x.
1021 if (op1.maybe_isnan ())
1022 r.set_varying (type);
1023 else
1024 build_le (r, type, op1);
1025 break;
1027 default:
1028 break;
1030 return true;
1034 // Check if the LHS range indicates a relation between OP1 and OP2.
1036 relation_kind
1037 operator_lt::op1_op2_relation (const irange &lhs, const frange &,
1038 const frange &) const
1040 if (lhs.undefined_p ())
1041 return VREL_UNDEFINED;
1043 // FALSE = op1 < op2 indicates GE_EXPR.
1044 if (lhs.zero_p ())
1045 return VREL_GE;
1047 // TRUE = op1 < op2 indicates LT_EXPR.
1048 if (!contains_zero_p (lhs))
1049 return VREL_LT;
1050 return VREL_VARYING;
1053 bool
1054 operator_le::fold_range (irange &r, tree type,
1055 const frange &op1, const frange &op2,
1056 relation_trio rel) const
1058 if (frelop_early_resolve (r, type, op1, op2, rel, VREL_LE))
1059 return true;
1061 if (op1.known_isnan ()
1062 || op2.known_isnan ()
1063 || !real_compare (LE_EXPR, &op1.lower_bound (), &op2.upper_bound ()))
1064 r = range_false (type);
1065 else if (!maybe_isnan (op1, op2)
1066 && real_compare (LE_EXPR, &op1.upper_bound (), &op2.lower_bound ()))
1067 r = range_true (type);
1068 else
1069 r = range_true_and_false (type);
1070 return true;
1073 bool
1074 operator_le::op1_range (frange &r,
1075 tree type,
1076 const irange &lhs,
1077 const frange &op2,
1078 relation_trio) const
1080 switch (get_bool_state (r, lhs, type))
1082 case BRS_TRUE:
1083 // The TRUE side of x <= NAN is unreachable.
1084 if (op2.known_isnan ())
1085 r.set_undefined ();
1086 else if (op2.undefined_p ())
1087 return false;
1088 else if (build_le (r, type, op2))
1089 r.clear_nan ();
1090 break;
1092 case BRS_FALSE:
1093 // On the FALSE side of x <= NAN, we know nothing about x.
1094 if (op2.maybe_isnan ())
1095 r.set_varying (type);
1096 else
1097 build_gt (r, type, op2);
1098 break;
1100 default:
1101 break;
1103 return true;
1106 bool
1107 operator_le::op2_range (frange &r,
1108 tree type,
1109 const irange &lhs,
1110 const frange &op1,
1111 relation_trio) const
1113 switch (get_bool_state (r, lhs, type))
1115 case BRS_TRUE:
1116 // The TRUE side of NAN <= x is unreachable.
1117 if (op1.known_isnan ())
1118 r.set_undefined ();
1119 else if (op1.undefined_p ())
1120 return false;
1121 else if (build_ge (r, type, op1))
1122 r.clear_nan ();
1123 break;
1125 case BRS_FALSE:
1126 // On the FALSE side of NAN <= x, we know nothing about x.
1127 if (op1.maybe_isnan ())
1128 r.set_varying (type);
1129 else if (op1.undefined_p ())
1130 return false;
1131 else
1132 build_lt (r, type, op1);
1133 break;
1135 default:
1136 break;
1138 return true;
1141 // Check if the LHS range indicates a relation between OP1 and OP2.
1143 relation_kind
1144 operator_le::op1_op2_relation (const irange &lhs, const frange &,
1145 const frange &) const
1147 if (lhs.undefined_p ())
1148 return VREL_UNDEFINED;
1150 // FALSE = op1 <= op2 indicates GT_EXPR.
1151 if (lhs.zero_p ())
1152 return VREL_GT;
1154 // TRUE = op1 <= op2 indicates LE_EXPR.
1155 if (!contains_zero_p (lhs))
1156 return VREL_LE;
1157 return VREL_VARYING;
1160 bool
1161 operator_gt::fold_range (irange &r, tree type,
1162 const frange &op1, const frange &op2,
1163 relation_trio trio) const
1165 relation_kind rel = trio.op1_op2 ();
1167 // VREL_EQ & GT_EXPR is impossible, even with NANs.
1168 if (rel == VREL_EQ)
1170 r = range_false (type);
1171 return true;
1173 if (frelop_early_resolve (r, type, op1, op2, trio, VREL_GT))
1174 return true;
1176 if (op1.known_isnan ()
1177 || op2.known_isnan ()
1178 || !real_compare (GT_EXPR, &op1.upper_bound (), &op2.lower_bound ()))
1179 r = range_false (type);
1180 else if (!maybe_isnan (op1, op2)
1181 && real_compare (GT_EXPR, &op1.lower_bound (), &op2.upper_bound ()))
1182 r = range_true (type);
1183 else
1184 r = range_true_and_false (type);
1185 return true;
1188 bool
1189 operator_gt::op1_range (frange &r,
1190 tree type,
1191 const irange &lhs,
1192 const frange &op2,
1193 relation_trio) const
1195 switch (get_bool_state (r, lhs, type))
1197 case BRS_TRUE:
1198 // The TRUE side of x > NAN is unreachable.
1199 if (op2.known_isnan ())
1200 r.set_undefined ();
1201 else if (op2.undefined_p ())
1202 return false;
1203 else if (build_gt (r, type, op2))
1205 r.clear_nan ();
1206 // x > y implies x is not -INF.
1207 frange_drop_ninf (r, type);
1209 break;
1211 case BRS_FALSE:
1212 // On the FALSE side of x > NAN, we know nothing about x.
1213 if (op2.maybe_isnan ())
1214 r.set_varying (type);
1215 else if (op2.undefined_p ())
1216 return false;
1217 else
1218 build_le (r, type, op2);
1219 break;
1221 default:
1222 break;
1224 return true;
1227 bool
1228 operator_gt::op2_range (frange &r,
1229 tree type,
1230 const irange &lhs,
1231 const frange &op1,
1232 relation_trio) const
1234 switch (get_bool_state (r, lhs, type))
1236 case BRS_TRUE:
1237 // The TRUE side of NAN > x is unreachable.
1238 if (op1.known_isnan ())
1239 r.set_undefined ();
1240 else if (op1.undefined_p ())
1241 return false;
1242 else if (build_lt (r, type, op1))
1244 r.clear_nan ();
1245 // x > y implies y is not +INF.
1246 frange_drop_inf (r, type);
1248 break;
1250 case BRS_FALSE:
1251 // On The FALSE side of NAN > x, we know nothing about x.
1252 if (op1.maybe_isnan ())
1253 r.set_varying (type);
1254 else if (op1.undefined_p ())
1255 return false;
1256 else
1257 build_ge (r, type, op1);
1258 break;
1260 default:
1261 break;
1263 return true;
1266 // Check if the LHS range indicates a relation between OP1 and OP2.
1268 relation_kind
1269 operator_gt::op1_op2_relation (const irange &lhs, const frange &,
1270 const frange &) const
1272 if (lhs.undefined_p ())
1273 return VREL_UNDEFINED;
1275 // FALSE = op1 > op2 indicates LE_EXPR.
1276 if (lhs.zero_p ())
1277 return VREL_LE;
1279 // TRUE = op1 > op2 indicates GT_EXPR.
1280 if (!contains_zero_p (lhs))
1281 return VREL_GT;
1282 return VREL_VARYING;
1285 bool
1286 operator_ge::fold_range (irange &r, tree type,
1287 const frange &op1, const frange &op2,
1288 relation_trio rel) const
1290 if (frelop_early_resolve (r, type, op1, op2, rel, VREL_GE))
1291 return true;
1293 if (op1.known_isnan ()
1294 || op2.known_isnan ()
1295 || !real_compare (GE_EXPR, &op1.upper_bound (), &op2.lower_bound ()))
1296 r = range_false (type);
1297 else if (!maybe_isnan (op1, op2)
1298 && real_compare (GE_EXPR, &op1.lower_bound (), &op2.upper_bound ()))
1299 r = range_true (type);
1300 else
1301 r = range_true_and_false (type);
1302 return true;
1305 bool
1306 operator_ge::op1_range (frange &r,
1307 tree type,
1308 const irange &lhs,
1309 const frange &op2,
1310 relation_trio) const
1312 switch (get_bool_state (r, lhs, type))
1314 case BRS_TRUE:
1315 // The TRUE side of x >= NAN is unreachable.
1316 if (op2.known_isnan ())
1317 r.set_undefined ();
1318 else if (op2.undefined_p ())
1319 return false;
1320 else if (build_ge (r, type, op2))
1321 r.clear_nan ();
1322 break;
1324 case BRS_FALSE:
1325 // On the FALSE side of x >= NAN, we know nothing about x.
1326 if (op2.maybe_isnan ())
1327 r.set_varying (type);
1328 else if (op2.undefined_p ())
1329 return false;
1330 else
1331 build_lt (r, type, op2);
1332 break;
1334 default:
1335 break;
1337 return true;
1340 bool
1341 operator_ge::op2_range (frange &r, tree type,
1342 const irange &lhs,
1343 const frange &op1,
1344 relation_trio) const
1346 switch (get_bool_state (r, lhs, type))
1348 case BRS_TRUE:
1349 // The TRUE side of NAN >= x is unreachable.
1350 if (op1.known_isnan ())
1351 r.set_undefined ();
1352 else if (op1.undefined_p ())
1353 return false;
1354 else if (build_le (r, type, op1))
1355 r.clear_nan ();
1356 break;
1358 case BRS_FALSE:
1359 // On the FALSE side of NAN >= x, we know nothing about x.
1360 if (op1.maybe_isnan ())
1361 r.set_varying (type);
1362 else if (op1.undefined_p ())
1363 return false;
1364 else
1365 build_gt (r, type, op1);
1366 break;
1368 default:
1369 break;
1371 return true;
1374 // Check if the LHS range indicates a relation between OP1 and OP2.
1376 relation_kind
1377 operator_ge::op1_op2_relation (const irange &lhs, const frange &,
1378 const frange &) const
1380 if (lhs.undefined_p ())
1381 return VREL_UNDEFINED;
1383 // FALSE = op1 >= op2 indicates LT_EXPR.
1384 if (lhs.zero_p ())
1385 return VREL_LT;
1387 // TRUE = op1 >= op2 indicates GE_EXPR.
1388 if (!contains_zero_p (lhs))
1389 return VREL_GE;
1390 return VREL_VARYING;
1393 // UNORDERED_EXPR comparison.
1395 class foperator_unordered : public range_operator
1397 using range_operator::fold_range;
1398 using range_operator::op1_range;
1399 using range_operator::op2_range;
1400 public:
1401 bool fold_range (irange &r, tree type,
1402 const frange &op1, const frange &op2,
1403 relation_trio = TRIO_VARYING) const final override;
1404 bool op1_range (frange &r, tree type,
1405 const irange &lhs, const frange &op2,
1406 relation_trio = TRIO_VARYING) const final override;
1407 bool op2_range (frange &r, tree type,
1408 const irange &lhs, const frange &op1,
1409 relation_trio rel = TRIO_VARYING) const final override
1411 return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
1413 } fop_unordered;
1415 bool
1416 foperator_unordered::fold_range (irange &r, tree type,
1417 const frange &op1, const frange &op2,
1418 relation_trio) const
1420 // UNORDERED is TRUE if either operand is a NAN.
1421 if (op1.known_isnan () || op2.known_isnan ())
1422 r = range_true (type);
1423 // UNORDERED is FALSE if neither operand is a NAN.
1424 else if (!op1.maybe_isnan () && !op2.maybe_isnan ())
1425 r = range_false (type);
1426 else
1427 r = range_true_and_false (type);
1428 return true;
1431 bool
1432 foperator_unordered::op1_range (frange &r, tree type,
1433 const irange &lhs,
1434 const frange &op2,
1435 relation_trio trio) const
1437 relation_kind rel = trio.op1_op2 ();
1438 switch (get_bool_state (r, lhs, type))
1440 case BRS_TRUE:
1441 // Since at least one operand must be NAN, if one of them is
1442 // not, the other must be.
1443 if (rel == VREL_EQ || !op2.maybe_isnan ())
1444 r.set_nan (type);
1445 else
1446 r.set_varying (type);
1447 break;
1449 case BRS_FALSE:
1450 // A false UNORDERED means both operands are !NAN, so it's
1451 // impossible for op2 to be a NAN.
1452 if (op2.known_isnan ())
1453 r.set_undefined ();
1454 else
1456 r.set_varying (type);
1457 r.clear_nan ();
1459 break;
1461 default:
1462 break;
1464 return true;
1467 // ORDERED_EXPR comparison.
1469 class foperator_ordered : public range_operator
1471 using range_operator::fold_range;
1472 using range_operator::op1_range;
1473 using range_operator::op2_range;
1474 public:
1475 bool fold_range (irange &r, tree type,
1476 const frange &op1, const frange &op2,
1477 relation_trio = TRIO_VARYING) const final override;
1478 bool op1_range (frange &r, tree type,
1479 const irange &lhs, const frange &op2,
1480 relation_trio = TRIO_VARYING) const final override;
1481 bool op2_range (frange &r, tree type,
1482 const irange &lhs, const frange &op1,
1483 relation_trio rel = TRIO_VARYING) const final override
1485 return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
1487 } fop_ordered;
1489 bool
1490 foperator_ordered::fold_range (irange &r, tree type,
1491 const frange &op1, const frange &op2,
1492 relation_trio) const
1494 if (op1.known_isnan () || op2.known_isnan ())
1495 r = range_false (type);
1496 else if (!op1.maybe_isnan () && !op2.maybe_isnan ())
1497 r = range_true (type);
1498 else
1499 r = range_true_and_false (type);
1500 return true;
1503 bool
1504 foperator_ordered::op1_range (frange &r, tree type,
1505 const irange &lhs,
1506 const frange &op2,
1507 relation_trio trio) const
1509 relation_kind rel = trio.op1_op2 ();
1510 switch (get_bool_state (r, lhs, type))
1512 case BRS_TRUE:
1513 // The TRUE side of ORDERED means both operands are !NAN, so
1514 // it's impossible for op2 to be a NAN.
1515 if (op2.known_isnan ())
1516 r.set_undefined ();
1517 else
1519 r.set_varying (type);
1520 r.clear_nan ();
1522 break;
1524 case BRS_FALSE:
1525 // The FALSE side of op1 ORDERED op1 implies op1 is NAN.
1526 if (rel == VREL_EQ)
1527 r.set_nan (type);
1528 else
1529 r.set_varying (type);
1530 break;
1532 default:
1533 break;
1535 return true;
1538 bool
1539 operator_negate::fold_range (frange &r, tree type,
1540 const frange &op1, const frange &op2,
1541 relation_trio) const
1543 if (empty_range_varying (r, type, op1, op2))
1544 return true;
1545 if (op1.known_isnan ())
1547 bool sign;
1548 if (op1.nan_signbit_p (sign))
1549 r.set_nan (type, !sign);
1550 else
1551 r.set_nan (type);
1552 return true;
1555 REAL_VALUE_TYPE lh_lb = op1.lower_bound ();
1556 REAL_VALUE_TYPE lh_ub = op1.upper_bound ();
1557 lh_lb = real_value_negate (&lh_lb);
1558 lh_ub = real_value_negate (&lh_ub);
1559 r.set (type, lh_ub, lh_lb);
1560 if (op1.maybe_isnan ())
1562 bool sign;
1563 if (op1.nan_signbit_p (sign))
1564 r.update_nan (!sign);
1565 else
1566 r.update_nan ();
1568 else
1569 r.clear_nan ();
1570 return true;
1573 bool
1574 operator_negate::op1_range (frange &r, tree type,
1575 const frange &lhs, const frange &op2,
1576 relation_trio rel) const
1578 return fold_range (r, type, lhs, op2, rel);
1581 bool
1582 operator_abs::fold_range (frange &r, tree type,
1583 const frange &op1, const frange &op2,
1584 relation_trio) const
1586 if (empty_range_varying (r, type, op1, op2))
1587 return true;
1588 if (op1.known_isnan ())
1590 r.set_nan (type, /*sign=*/false);
1591 return true;
1594 const REAL_VALUE_TYPE lh_lb = op1.lower_bound ();
1595 const REAL_VALUE_TYPE lh_ub = op1.upper_bound ();
1596 // Handle the easy case where everything is positive.
1597 if (real_compare (GE_EXPR, &lh_lb, &dconst0)
1598 && !real_iszero (&lh_lb, /*sign=*/true)
1599 && !op1.maybe_isnan (/*sign=*/true))
1601 r = op1;
1602 return true;
1605 REAL_VALUE_TYPE min = real_value_abs (&lh_lb);
1606 REAL_VALUE_TYPE max = real_value_abs (&lh_ub);
1607 // If the range contains zero then we know that the minimum value in the
1608 // range will be zero.
1609 if (real_compare (LE_EXPR, &lh_lb, &dconst0)
1610 && real_compare (GE_EXPR, &lh_ub, &dconst0))
1612 if (real_compare (GT_EXPR, &min, &max))
1613 max = min;
1614 min = dconst0;
1616 else
1618 // If the range was reversed, swap MIN and MAX.
1619 if (real_compare (GT_EXPR, &min, &max))
1620 std::swap (min, max);
1623 r.set (type, min, max);
1624 if (op1.maybe_isnan ())
1625 r.update_nan (/*sign=*/false);
1626 else
1627 r.clear_nan ();
1628 return true;
1631 bool
1632 operator_abs::op1_range (frange &r, tree type,
1633 const frange &lhs, const frange &op2,
1634 relation_trio) const
1636 if (empty_range_varying (r, type, lhs, op2))
1637 return true;
1638 if (lhs.known_isnan ())
1640 r.set_nan (type);
1641 return true;
1644 // Start with the positives because negatives are an impossible result.
1645 frange positives (type, dconst0, frange_val_max (type));
1646 positives.update_nan (/*sign=*/false);
1647 positives.intersect (lhs);
1648 r = positives;
1649 // Add -NAN if relevant.
1650 if (r.maybe_isnan ())
1652 frange neg_nan;
1653 neg_nan.set_nan (type, true);
1654 r.union_ (neg_nan);
1656 if (r.known_isnan () || r.undefined_p ())
1657 return true;
1658 // Then add the negative of each pair:
1659 // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20].
1660 frange negatives (type, real_value_negate (&positives.upper_bound ()),
1661 real_value_negate (&positives.lower_bound ()));
1662 negatives.clear_nan ();
1663 r.union_ (negatives);
1664 return true;
1667 class foperator_unordered_lt : public range_operator
1669 using range_operator::fold_range;
1670 using range_operator::op1_range;
1671 using range_operator::op2_range;
1672 public:
1673 bool fold_range (irange &r, tree type,
1674 const frange &op1, const frange &op2,
1675 relation_trio trio = TRIO_VARYING) const final override
1677 relation_kind rel = trio.op1_op2 ();
1679 if (op1.known_isnan () || op2.known_isnan ()
1680 || rel == VREL_LT)
1682 r = range_true (type);
1683 return true;
1685 frange op1_no_nan = op1;
1686 frange op2_no_nan = op2;
1687 if (op1.maybe_isnan ())
1688 op1_no_nan.clear_nan ();
1689 if (op2.maybe_isnan ())
1690 op2_no_nan.clear_nan ();
1691 if (!range_op_handler (LT_EXPR).fold_range (r, type, op1_no_nan,
1692 op2_no_nan, trio))
1693 return false;
1694 // The result is the same as the ordered version when the
1695 // comparison is true or when the operands cannot be NANs.
1696 if (!maybe_isnan (op1, op2) || r == range_true (type))
1697 return true;
1698 else
1700 r = range_true_and_false (type);
1701 return true;
1704 bool op1_range (frange &r, tree type,
1705 const irange &lhs,
1706 const frange &op2,
1707 relation_trio trio) const final override;
1708 bool op2_range (frange &r, tree type,
1709 const irange &lhs,
1710 const frange &op1,
1711 relation_trio trio) const final override;
1712 } fop_unordered_lt;
1714 bool
1715 foperator_unordered_lt::op1_range (frange &r, tree type,
1716 const irange &lhs,
1717 const frange &op2,
1718 relation_trio) const
1720 switch (get_bool_state (r, lhs, type))
1722 case BRS_TRUE:
1723 if (op2.maybe_isnan ())
1724 r.set_varying (type);
1725 else if (op2.undefined_p ())
1726 return false;
1727 else
1728 build_lt (r, type, op2);
1729 break;
1731 case BRS_FALSE:
1732 // A false UNORDERED_LT means both operands are !NAN, so it's
1733 // impossible for op2 to be a NAN.
1734 if (op2.known_isnan ())
1735 r.set_undefined ();
1736 else if (op2.undefined_p ())
1737 return false;
1738 else if (build_ge (r, type, op2))
1739 r.clear_nan ();
1740 break;
1742 default:
1743 break;
1745 return true;
1748 bool
1749 foperator_unordered_lt::op2_range (frange &r, tree type,
1750 const irange &lhs,
1751 const frange &op1,
1752 relation_trio) const
1754 switch (get_bool_state (r, lhs, type))
1756 case BRS_TRUE:
1757 if (op1.maybe_isnan ())
1758 r.set_varying (type);
1759 else if (op1.undefined_p ())
1760 return false;
1761 else
1762 build_gt (r, type, op1);
1763 break;
1765 case BRS_FALSE:
1766 // A false UNORDERED_LT means both operands are !NAN, so it's
1767 // impossible for op1 to be a NAN.
1768 if (op1.known_isnan ())
1769 r.set_undefined ();
1770 else if (op1.undefined_p ())
1771 return false;
1772 else if (build_le (r, type, op1))
1773 r.clear_nan ();
1774 break;
1776 default:
1777 break;
1779 return true;
1782 class foperator_unordered_le : public range_operator
1784 using range_operator::fold_range;
1785 using range_operator::op1_range;
1786 using range_operator::op2_range;
1787 public:
1788 bool fold_range (irange &r, tree type,
1789 const frange &op1, const frange &op2,
1790 relation_trio trio = TRIO_VARYING) const final override
1792 relation_kind rel = trio.op1_op2 ();
1794 if (op1.known_isnan () || op2.known_isnan ()
1795 || rel == VREL_LE)
1797 r = range_true (type);
1798 return true;
1800 frange op1_no_nan = op1;
1801 frange op2_no_nan = op2;
1802 if (op1.maybe_isnan ())
1803 op1_no_nan.clear_nan ();
1804 if (op2.maybe_isnan ())
1805 op2_no_nan.clear_nan ();
1806 if (!range_op_handler (LE_EXPR).fold_range (r, type, op1_no_nan,
1807 op2_no_nan, trio))
1808 return false;
1809 // The result is the same as the ordered version when the
1810 // comparison is true or when the operands cannot be NANs.
1811 if (!maybe_isnan (op1, op2) || r == range_true (type))
1812 return true;
1813 else
1815 r = range_true_and_false (type);
1816 return true;
1819 bool op1_range (frange &r, tree type,
1820 const irange &lhs, const frange &op2,
1821 relation_trio = TRIO_VARYING) const final override;
1822 bool op2_range (frange &r, tree type,
1823 const irange &lhs, const frange &op1,
1824 relation_trio = TRIO_VARYING) const final override;
1825 } fop_unordered_le;
1827 bool
1828 foperator_unordered_le::op1_range (frange &r, tree type,
1829 const irange &lhs, const frange &op2,
1830 relation_trio) const
1832 switch (get_bool_state (r, lhs, type))
1834 case BRS_TRUE:
1835 if (op2.maybe_isnan ())
1836 r.set_varying (type);
1837 else if (op2.undefined_p ())
1838 return false;
1839 else
1840 build_le (r, type, op2);
1841 break;
1843 case BRS_FALSE:
1844 // A false UNORDERED_LE means both operands are !NAN, so it's
1845 // impossible for op2 to be a NAN.
1846 if (op2.known_isnan ())
1847 r.set_undefined ();
1848 else if (build_gt (r, type, op2))
1849 r.clear_nan ();
1850 break;
1852 default:
1853 break;
1855 return true;
1858 bool
1859 foperator_unordered_le::op2_range (frange &r,
1860 tree type,
1861 const irange &lhs,
1862 const frange &op1,
1863 relation_trio) const
1865 switch (get_bool_state (r, lhs, type))
1867 case BRS_TRUE:
1868 if (op1.maybe_isnan ())
1869 r.set_varying (type);
1870 else if (op1.undefined_p ())
1871 return false;
1872 else
1873 build_ge (r, type, op1);
1874 break;
1876 case BRS_FALSE:
1877 // A false UNORDERED_LE means both operands are !NAN, so it's
1878 // impossible for op1 to be a NAN.
1879 if (op1.known_isnan ())
1880 r.set_undefined ();
1881 else if (op1.undefined_p ())
1882 return false;
1883 else if (build_lt (r, type, op1))
1884 r.clear_nan ();
1885 break;
1887 default:
1888 break;
1890 return true;
1893 class foperator_unordered_gt : public range_operator
1895 using range_operator::fold_range;
1896 using range_operator::op1_range;
1897 using range_operator::op2_range;
1898 public:
1899 bool fold_range (irange &r, tree type,
1900 const frange &op1, const frange &op2,
1901 relation_trio trio = TRIO_VARYING) const final override
1903 relation_kind rel = trio.op1_op2 ();
1905 if (op1.known_isnan () || op2.known_isnan ()
1906 || rel == VREL_GT)
1908 r = range_true (type);
1909 return true;
1911 frange op1_no_nan = op1;
1912 frange op2_no_nan = op2;
1913 if (op1.maybe_isnan ())
1914 op1_no_nan.clear_nan ();
1915 if (op2.maybe_isnan ())
1916 op2_no_nan.clear_nan ();
1917 if (!range_op_handler (GT_EXPR).fold_range (r, type, op1_no_nan,
1918 op2_no_nan, trio))
1919 return false;
1920 // The result is the same as the ordered version when the
1921 // comparison is true or when the operands cannot be NANs.
1922 if (!maybe_isnan (op1, op2) || r == range_true (type))
1923 return true;
1924 else
1926 r = range_true_and_false (type);
1927 return true;
1930 bool op1_range (frange &r, tree type,
1931 const irange &lhs, const frange &op2,
1932 relation_trio = TRIO_VARYING) const final override;
1933 bool op2_range (frange &r, tree type,
1934 const irange &lhs, const frange &op1,
1935 relation_trio = TRIO_VARYING) const final override;
1936 } fop_unordered_gt;
1938 bool
1939 foperator_unordered_gt::op1_range (frange &r,
1940 tree type,
1941 const irange &lhs,
1942 const frange &op2,
1943 relation_trio) const
1945 switch (get_bool_state (r, lhs, type))
1947 case BRS_TRUE:
1948 if (op2.maybe_isnan ())
1949 r.set_varying (type);
1950 else if (op2.undefined_p ())
1951 return false;
1952 else
1953 build_gt (r, type, op2);
1954 break;
1956 case BRS_FALSE:
1957 // A false UNORDERED_GT means both operands are !NAN, so it's
1958 // impossible for op2 to be a NAN.
1959 if (op2.known_isnan ())
1960 r.set_undefined ();
1961 else if (op2.undefined_p ())
1962 return false;
1963 else if (build_le (r, type, op2))
1964 r.clear_nan ();
1965 break;
1967 default:
1968 break;
1970 return true;
1973 bool
1974 foperator_unordered_gt::op2_range (frange &r,
1975 tree type,
1976 const irange &lhs,
1977 const frange &op1,
1978 relation_trio) const
1980 switch (get_bool_state (r, lhs, type))
1982 case BRS_TRUE:
1983 if (op1.maybe_isnan ())
1984 r.set_varying (type);
1985 else if (op1.undefined_p ())
1986 return false;
1987 else
1988 build_lt (r, type, op1);
1989 break;
1991 case BRS_FALSE:
1992 // A false UNORDERED_GT means both operands are !NAN, so it's
1993 // impossible for op1 to be a NAN.
1994 if (op1.known_isnan ())
1995 r.set_undefined ();
1996 else if (op1.undefined_p ())
1997 return false;
1998 else if (build_ge (r, type, op1))
1999 r.clear_nan ();
2000 break;
2002 default:
2003 break;
2005 return true;
2008 class foperator_unordered_ge : public range_operator
2010 using range_operator::fold_range;
2011 using range_operator::op1_range;
2012 using range_operator::op2_range;
2013 public:
2014 bool fold_range (irange &r, tree type,
2015 const frange &op1, const frange &op2,
2016 relation_trio trio = TRIO_VARYING) const final override
2018 relation_kind rel = trio.op1_op2 ();
2020 if (op1.known_isnan () || op2.known_isnan ()
2021 || rel == VREL_GE)
2023 r = range_true (type);
2024 return true;
2026 frange op1_no_nan = op1;
2027 frange op2_no_nan = op2;
2028 if (op1.maybe_isnan ())
2029 op1_no_nan.clear_nan ();
2030 if (op2.maybe_isnan ())
2031 op2_no_nan.clear_nan ();
2032 if (!range_op_handler (GE_EXPR).fold_range (r, type, op1_no_nan,
2033 op2_no_nan, trio))
2034 return false;
2035 // The result is the same as the ordered version when the
2036 // comparison is true or when the operands cannot be NANs.
2037 if (!maybe_isnan (op1, op2) || r == range_true (type))
2038 return true;
2039 else
2041 r = range_true_and_false (type);
2042 return true;
2045 bool op1_range (frange &r, tree type,
2046 const irange &lhs, const frange &op2,
2047 relation_trio = TRIO_VARYING) const final override;
2048 bool op2_range (frange &r, tree type,
2049 const irange &lhs, const frange &op1,
2050 relation_trio = TRIO_VARYING) const final override;
2051 } fop_unordered_ge;
2053 bool
2054 foperator_unordered_ge::op1_range (frange &r,
2055 tree type,
2056 const irange &lhs,
2057 const frange &op2,
2058 relation_trio) const
2060 switch (get_bool_state (r, lhs, type))
2062 case BRS_TRUE:
2063 if (op2.maybe_isnan ())
2064 r.set_varying (type);
2065 else if (op2.undefined_p ())
2066 return false;
2067 else
2068 build_ge (r, type, op2);
2069 break;
2071 case BRS_FALSE:
2072 // A false UNORDERED_GE means both operands are !NAN, so it's
2073 // impossible for op2 to be a NAN.
2074 if (op2.known_isnan ())
2075 r.set_undefined ();
2076 else if (op2.undefined_p ())
2077 return false;
2078 else if (build_lt (r, type, op2))
2079 r.clear_nan ();
2080 break;
2082 default:
2083 break;
2085 return true;
2088 bool
2089 foperator_unordered_ge::op2_range (frange &r, tree type,
2090 const irange &lhs,
2091 const frange &op1,
2092 relation_trio) const
2094 switch (get_bool_state (r, lhs, type))
2096 case BRS_TRUE:
2097 if (op1.maybe_isnan ())
2098 r.set_varying (type);
2099 else if (op1.undefined_p ())
2100 return false;
2101 else
2102 build_le (r, type, op1);
2103 break;
2105 case BRS_FALSE:
2106 // A false UNORDERED_GE means both operands are !NAN, so it's
2107 // impossible for op1 to be a NAN.
2108 if (op1.known_isnan ())
2109 r.set_undefined ();
2110 else if (op1.undefined_p ())
2111 return false;
2112 else if (build_gt (r, type, op1))
2113 r.clear_nan ();
2114 break;
2116 default:
2117 break;
2119 return true;
2122 class foperator_unordered_equal : public range_operator
2124 using range_operator::fold_range;
2125 using range_operator::op1_range;
2126 using range_operator::op2_range;
2127 public:
2128 bool fold_range (irange &r, tree type,
2129 const frange &op1, const frange &op2,
2130 relation_trio trio = TRIO_VARYING) const final override
2132 relation_kind rel = trio.op1_op2 ();
2134 if (op1.known_isnan () || op2.known_isnan ()
2135 || rel == VREL_EQ)
2137 r = range_true (type);
2138 return true;
2140 frange op1_no_nan = op1;
2141 frange op2_no_nan = op2;
2142 if (op1.maybe_isnan ())
2143 op1_no_nan.clear_nan ();
2144 if (op2.maybe_isnan ())
2145 op2_no_nan.clear_nan ();
2146 if (!range_op_handler (EQ_EXPR).fold_range (r, type, op1_no_nan,
2147 op2_no_nan, trio))
2148 return false;
2149 // The result is the same as the ordered version when the
2150 // comparison is true or when the operands cannot be NANs.
2151 if (!maybe_isnan (op1, op2) || r == range_true (type))
2152 return true;
2153 else
2155 r = range_true_and_false (type);
2156 return true;
2159 bool op1_range (frange &r, tree type,
2160 const irange &lhs, const frange &op2,
2161 relation_trio = TRIO_VARYING) const final override;
2162 bool op2_range (frange &r, tree type,
2163 const irange &lhs, const frange &op1,
2164 relation_trio rel = TRIO_VARYING) const final override
2166 return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
2168 } fop_unordered_equal;
2170 bool
2171 foperator_unordered_equal::op1_range (frange &r, tree type,
2172 const irange &lhs,
2173 const frange &op2,
2174 relation_trio) const
2176 switch (get_bool_state (r, lhs, type))
2178 case BRS_TRUE:
2179 // If it's true, the result is the same as OP2 plus a NAN.
2180 r = op2;
2181 // Add both zeros if there's the possibility of zero equality.
2182 frange_add_zeros (r, type);
2183 // Add the possibility of a NAN.
2184 r.update_nan ();
2185 break;
2187 case BRS_FALSE:
2188 // A false UNORDERED_EQ means both operands are !NAN, so it's
2189 // impossible for op2 to be a NAN.
2190 if (op2.known_isnan ())
2191 r.set_undefined ();
2192 else
2194 // The false side indicates !NAN and not equal. We can at least
2195 // represent !NAN.
2196 r.set_varying (type);
2197 r.clear_nan ();
2199 break;
2201 default:
2202 break;
2204 return true;
2207 class foperator_ltgt : public range_operator
2209 using range_operator::fold_range;
2210 using range_operator::op1_range;
2211 using range_operator::op2_range;
2212 public:
2213 bool fold_range (irange &r, tree type,
2214 const frange &op1, const frange &op2,
2215 relation_trio trio = TRIO_VARYING) const final override
2217 if (op1.known_isnan () || op2.known_isnan ())
2219 r = range_false (type);
2220 return true;
2222 frange op1_no_nan = op1;
2223 frange op2_no_nan = op2;
2224 if (op1.maybe_isnan ())
2225 op1_no_nan.clear_nan ();
2226 if (op2.maybe_isnan ())
2227 op2_no_nan.clear_nan ();
2228 if (!range_op_handler (NE_EXPR).fold_range (r, type, op1_no_nan,
2229 op2_no_nan, trio))
2230 return false;
2231 // The result is the same as the ordered version when the
2232 // comparison is true or when the operands cannot be NANs.
2233 if (!maybe_isnan (op1, op2) || r == range_false (type))
2234 return true;
2235 else
2237 r = range_true_and_false (type);
2238 return true;
2241 bool op1_range (frange &r, tree type,
2242 const irange &lhs, const frange &op2,
2243 relation_trio = TRIO_VARYING) const final override;
2244 bool op2_range (frange &r, tree type,
2245 const irange &lhs, const frange &op1,
2246 relation_trio rel = TRIO_VARYING) const final override
2248 return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
2250 } fop_ltgt;
2252 bool
2253 foperator_ltgt::op1_range (frange &r, tree type,
2254 const irange &lhs,
2255 const frange &op2,
2256 relation_trio) const
2258 switch (get_bool_state (r, lhs, type))
2260 case BRS_TRUE:
2261 // A true LTGT means both operands are !NAN, so it's
2262 // impossible for op2 to be a NAN.
2263 if (op2.known_isnan ())
2264 r.set_undefined ();
2265 else
2267 // The true side indicates !NAN and not equal. We can at least
2268 // represent !NAN.
2269 r.set_varying (type);
2270 r.clear_nan ();
2272 break;
2274 case BRS_FALSE:
2275 // If it's false, the result is the same as OP2 plus a NAN.
2276 r = op2;
2277 // Add both zeros if there's the possibility of zero equality.
2278 frange_add_zeros (r, type);
2279 // Add the possibility of a NAN.
2280 r.update_nan ();
2281 break;
2283 default:
2284 break;
2286 return true;
2289 // Final tweaks for float binary op op1_range/op2_range.
2290 // Return TRUE if the operation is performed and a valid range is available.
2292 static bool
2293 float_binary_op_range_finish (bool ret, frange &r, tree type,
2294 const frange &lhs, bool div_op2 = false)
2296 if (!ret)
2297 return false;
2299 // If we get a known NAN from reverse op, it means either that
2300 // the other operand was known NAN (in that case we know nothing),
2301 // or the reverse operation introduced a known NAN.
2302 // Say for lhs = op1 * op2 if lhs is [-0, +0] and op2 is too,
2303 // 0 / 0 is known NAN. Just punt in that case.
2304 // If NANs aren't honored, we get for 0 / 0 UNDEFINED, so punt as well.
2305 // Or if lhs is a known NAN, we also don't know anything.
2306 if (r.known_isnan () || lhs.known_isnan () || r.undefined_p ())
2308 r.set_varying (type);
2309 return true;
2312 // If lhs isn't NAN, then neither operand could be NAN,
2313 // even if the reverse operation does introduce a maybe_nan.
2314 if (!lhs.maybe_isnan ())
2316 r.clear_nan ();
2317 if (div_op2
2318 ? !(real_compare (LE_EXPR, &lhs.lower_bound (), &dconst0)
2319 && real_compare (GE_EXPR, &lhs.upper_bound (), &dconst0))
2320 : !(real_isinf (&lhs.lower_bound ())
2321 || real_isinf (&lhs.upper_bound ())))
2322 // For reverse + or - or * or op1 of /, if result is finite, then
2323 // r must be finite too, as X + INF or X - INF or X * INF or
2324 // INF / X is always +-INF or NAN. For op2 of /, if result is
2325 // non-zero and not NAN, r must be finite, as X / INF is always
2326 // 0 or NAN.
2327 frange_drop_infs (r, type);
2329 // If lhs is a maybe or known NAN, the operand could be
2330 // NAN.
2331 else
2332 r.update_nan ();
2333 return true;
2336 // True if [lb, ub] is [+-0, +-0].
2337 static bool
2338 zero_p (const REAL_VALUE_TYPE &lb, const REAL_VALUE_TYPE &ub)
2340 return real_iszero (&lb) && real_iszero (&ub);
2343 // True if +0 or -0 is in [lb, ub] range.
2344 static bool
2345 contains_zero_p (const REAL_VALUE_TYPE &lb, const REAL_VALUE_TYPE &ub)
2347 return (real_compare (LE_EXPR, &lb, &dconst0)
2348 && real_compare (GE_EXPR, &ub, &dconst0));
2351 // True if [lb, ub] is [-INF, -INF] or [+INF, +INF].
2352 static bool
2353 singleton_inf_p (const REAL_VALUE_TYPE &lb, const REAL_VALUE_TYPE &ub)
2355 return real_isinf (&lb) && real_isinf (&ub, real_isneg (&lb));
2358 // Return -1 if binary op result must have sign bit set,
2359 // 1 if binary op result must have sign bit clear,
2360 // 0 otherwise.
2361 // Sign bit of binary op result is exclusive or of the
2362 // operand's sign bits.
2363 static int
2364 signbit_known_p (const REAL_VALUE_TYPE &lh_lb, const REAL_VALUE_TYPE &lh_ub,
2365 const REAL_VALUE_TYPE &rh_lb, const REAL_VALUE_TYPE &rh_ub)
2367 if (real_isneg (&lh_lb) == real_isneg (&lh_ub)
2368 && real_isneg (&rh_lb) == real_isneg (&rh_ub))
2370 if (real_isneg (&lh_lb) == real_isneg (&rh_ub))
2371 return 1;
2372 else
2373 return -1;
2375 return 0;
2378 // Set [lb, ub] to [-0, -0], [-0, +0] or [+0, +0] depending on
2379 // signbit_known.
2380 static void
2381 zero_range (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, int signbit_known)
2383 ub = lb = dconst0;
2384 if (signbit_known <= 0)
2385 lb = dconstm0;
2386 if (signbit_known < 0)
2387 ub = lb;
2390 // Set [lb, ub] to [-INF, -INF], [-INF, +INF] or [+INF, +INF] depending on
2391 // signbit_known.
2392 static void
2393 inf_range (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, int signbit_known)
2395 if (signbit_known > 0)
2396 ub = lb = dconstinf;
2397 else if (signbit_known < 0)
2398 ub = lb = dconstninf;
2399 else
2401 lb = dconstninf;
2402 ub = dconstinf;
2406 // Set [lb, ub] to [-INF, -0], [-INF, +INF] or [+0, +INF] depending on
2407 // signbit_known.
2408 static void
2409 zero_to_inf_range (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, int signbit_known)
2411 if (signbit_known > 0)
2413 lb = dconst0;
2414 ub = dconstinf;
2416 else if (signbit_known < 0)
2418 lb = dconstninf;
2419 ub = dconstm0;
2421 else
2423 lb = dconstninf;
2424 ub = dconstinf;
2428 /* Extend the LHS range by 1ulp in each direction. For op1_range
2429 or op2_range of binary operations just computing the inverse
2430 operation on ranges isn't sufficient. Consider e.g.
2431 [1., 1.] = op1 + [1., 1.]. op1's range is not [0., 0.], but
2432 [-0x1.0p-54, 0x1.0p-53] (when not -frounding-math), any value for
2433 which adding 1. to it results in 1. after rounding to nearest.
2434 So, for op1_range/op2_range extend the lhs range by 1ulp (or 0.5ulp)
2435 in each direction. See PR109008 for more details. */
2437 static frange
2438 float_widen_lhs_range (tree type, const frange &lhs)
2440 frange ret = lhs;
2441 if (lhs.known_isnan ())
2442 return ret;
2443 REAL_VALUE_TYPE lb = lhs.lower_bound ();
2444 REAL_VALUE_TYPE ub = lhs.upper_bound ();
2445 if (real_isfinite (&lb))
2447 frange_nextafter (TYPE_MODE (type), lb, dconstninf);
2448 if (real_isinf (&lb))
2450 /* For -DBL_MAX, instead of -Inf use
2451 nexttoward (-DBL_MAX, -LDBL_MAX) in a hypothetical
2452 wider type with the same mantissa precision but larger
2453 exponent range; it is outside of range of double values,
2454 but makes it clear it is just one ulp larger rather than
2455 infinite amount larger. */
2456 lb = dconstm1;
2457 SET_REAL_EXP (&lb, FLOAT_MODE_FORMAT (TYPE_MODE (type))->emax + 1);
2459 if (!flag_rounding_math && !MODE_COMPOSITE_P (TYPE_MODE (type)))
2461 /* If not -frounding-math nor IBM double double, actually widen
2462 just by 0.5ulp rather than 1ulp. */
2463 REAL_VALUE_TYPE tem;
2464 real_arithmetic (&tem, PLUS_EXPR, &lhs.lower_bound (), &lb);
2465 real_arithmetic (&lb, RDIV_EXPR, &tem, &dconst2);
2468 if (real_isfinite (&ub))
2470 frange_nextafter (TYPE_MODE (type), ub, dconstinf);
2471 if (real_isinf (&ub))
2473 /* For DBL_MAX similarly. */
2474 ub = dconst1;
2475 SET_REAL_EXP (&ub, FLOAT_MODE_FORMAT (TYPE_MODE (type))->emax + 1);
2477 if (!flag_rounding_math && !MODE_COMPOSITE_P (TYPE_MODE (type)))
2479 /* If not -frounding-math nor IBM double double, actually widen
2480 just by 0.5ulp rather than 1ulp. */
2481 REAL_VALUE_TYPE tem;
2482 real_arithmetic (&tem, PLUS_EXPR, &lhs.upper_bound (), &ub);
2483 real_arithmetic (&ub, RDIV_EXPR, &tem, &dconst2);
2486 /* Temporarily disable -ffinite-math-only, so that frange::set doesn't
2487 reduce the range back to real_min_representable (type) as lower bound
2488 or real_max_representable (type) as upper bound. */
2489 bool save_flag_finite_math_only = flag_finite_math_only;
2490 flag_finite_math_only = false;
2491 ret.set (type, lb, ub, lhs.get_nan_state ());
2492 flag_finite_math_only = save_flag_finite_math_only;
2493 return ret;
2496 bool
2497 operator_plus::op1_range (frange &r, tree type, const frange &lhs,
2498 const frange &op2, relation_trio) const
2500 if (lhs.undefined_p ())
2501 return false;
2502 range_op_handler minus (MINUS_EXPR);
2503 if (!minus)
2504 return false;
2505 frange wlhs = float_widen_lhs_range (type, lhs);
2506 return float_binary_op_range_finish (minus.fold_range (r, type, wlhs, op2),
2507 r, type, wlhs);
2510 bool
2511 operator_plus::op2_range (frange &r, tree type,
2512 const frange &lhs, const frange &op1,
2513 relation_trio) const
2515 return op1_range (r, type, lhs, op1);
2518 void
2519 operator_plus::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
2520 bool &maybe_nan, tree type,
2521 const REAL_VALUE_TYPE &lh_lb,
2522 const REAL_VALUE_TYPE &lh_ub,
2523 const REAL_VALUE_TYPE &rh_lb,
2524 const REAL_VALUE_TYPE &rh_ub,
2525 relation_kind) const
2527 frange_arithmetic (PLUS_EXPR, type, lb, lh_lb, rh_lb, dconstninf);
2528 frange_arithmetic (PLUS_EXPR, type, ub, lh_ub, rh_ub, dconstinf);
2530 // [-INF] + [+INF] = NAN
2531 if (real_isinf (&lh_lb, true) && real_isinf (&rh_ub, false))
2532 maybe_nan = true;
2533 // [+INF] + [-INF] = NAN
2534 else if (real_isinf (&lh_ub, false) && real_isinf (&rh_lb, true))
2535 maybe_nan = true;
2536 else
2537 maybe_nan = false;
2541 bool
2542 operator_minus::op1_range (frange &r, tree type,
2543 const frange &lhs, const frange &op2,
2544 relation_trio) const
2546 if (lhs.undefined_p ())
2547 return false;
2548 frange wlhs = float_widen_lhs_range (type, lhs);
2549 return float_binary_op_range_finish (
2550 range_op_handler (PLUS_EXPR).fold_range (r, type, wlhs, op2),
2551 r, type, wlhs);
2554 bool
2555 operator_minus::op2_range (frange &r, tree type,
2556 const frange &lhs, const frange &op1,
2557 relation_trio) const
2559 if (lhs.undefined_p ())
2560 return false;
2561 frange wlhs = float_widen_lhs_range (type, lhs);
2562 return float_binary_op_range_finish (fold_range (r, type, op1, wlhs),
2563 r, type, wlhs);
2566 void
2567 operator_minus::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
2568 bool &maybe_nan, tree type,
2569 const REAL_VALUE_TYPE &lh_lb,
2570 const REAL_VALUE_TYPE &lh_ub,
2571 const REAL_VALUE_TYPE &rh_lb,
2572 const REAL_VALUE_TYPE &rh_ub,
2573 relation_kind) const
2575 frange_arithmetic (MINUS_EXPR, type, lb, lh_lb, rh_ub, dconstninf);
2576 frange_arithmetic (MINUS_EXPR, type, ub, lh_ub, rh_lb, dconstinf);
2578 // [+INF] - [+INF] = NAN
2579 if (real_isinf (&lh_ub, false) && real_isinf (&rh_ub, false))
2580 maybe_nan = true;
2581 // [-INF] - [-INF] = NAN
2582 else if (real_isinf (&lh_lb, true) && real_isinf (&rh_lb, true))
2583 maybe_nan = true;
2584 else
2585 maybe_nan = false;
2589 // Given CP[0] to CP[3] floating point values rounded to -INF,
2590 // set LB to the smallest of them (treating -0 as smaller to +0).
2591 // Given CP[4] to CP[7] floating point values rounded to +INF,
2592 // set UB to the largest of them (treating -0 as smaller to +0).
2594 static void
2595 find_range (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
2596 const REAL_VALUE_TYPE (&cp)[8])
2598 lb = cp[0];
2599 ub = cp[4];
2600 for (int i = 1; i < 4; ++i)
2602 if (real_less (&cp[i], &lb)
2603 || (real_iszero (&lb) && real_isnegzero (&cp[i])))
2604 lb = cp[i];
2605 if (real_less (&ub, &cp[i + 4])
2606 || (real_isnegzero (&ub) && real_iszero (&cp[i + 4])))
2607 ub = cp[i + 4];
2612 bool
2613 operator_mult::op1_range (frange &r, tree type,
2614 const frange &lhs, const frange &op2,
2615 relation_trio) const
2617 if (lhs.undefined_p ())
2618 return false;
2619 range_op_handler rdiv (RDIV_EXPR);
2620 if (!rdiv)
2621 return false;
2622 frange wlhs = float_widen_lhs_range (type, lhs);
2623 bool ret = rdiv.fold_range (r, type, wlhs, op2);
2624 if (ret == false)
2625 return false;
2626 if (wlhs.known_isnan () || op2.known_isnan () || op2.undefined_p ())
2627 return float_binary_op_range_finish (ret, r, type, wlhs);
2628 const REAL_VALUE_TYPE &lhs_lb = wlhs.lower_bound ();
2629 const REAL_VALUE_TYPE &lhs_ub = wlhs.upper_bound ();
2630 const REAL_VALUE_TYPE &op2_lb = op2.lower_bound ();
2631 const REAL_VALUE_TYPE &op2_ub = op2.upper_bound ();
2632 if ((contains_zero_p (lhs_lb, lhs_ub) && contains_zero_p (op2_lb, op2_ub))
2633 || ((real_isinf (&lhs_lb) || real_isinf (&lhs_ub))
2634 && (real_isinf (&op2_lb) || real_isinf (&op2_ub))))
2636 // If both lhs and op2 could be zeros or both could be infinities,
2637 // we don't know anything about op1 except maybe for the sign
2638 // and perhaps if it can be NAN or not.
2639 REAL_VALUE_TYPE lb, ub;
2640 int signbit_known = signbit_known_p (lhs_lb, lhs_ub, op2_lb, op2_ub);
2641 zero_to_inf_range (lb, ub, signbit_known);
2642 r.set (type, lb, ub);
2644 // Otherwise, if op2 is a singleton INF and lhs doesn't include INF,
2645 // or if lhs must be zero and op2 doesn't include zero, it would be
2646 // UNDEFINED, while rdiv.fold_range computes a zero or singleton INF
2647 // range. Those are supersets of UNDEFINED, so let's keep that way.
2648 return float_binary_op_range_finish (ret, r, type, wlhs);
2651 bool
2652 operator_mult::op2_range (frange &r, tree type,
2653 const frange &lhs, const frange &op1,
2654 relation_trio) const
2656 return op1_range (r, type, lhs, op1);
2659 void
2660 operator_mult::rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub,
2661 bool &maybe_nan, tree type,
2662 const REAL_VALUE_TYPE &lh_lb,
2663 const REAL_VALUE_TYPE &lh_ub,
2664 const REAL_VALUE_TYPE &rh_lb,
2665 const REAL_VALUE_TYPE &rh_ub,
2666 relation_kind kind) const
2668 bool is_square
2669 = (kind == VREL_EQ
2670 && real_equal (&lh_lb, &rh_lb)
2671 && real_equal (&lh_ub, &rh_ub)
2672 && real_isneg (&lh_lb) == real_isneg (&rh_lb)
2673 && real_isneg (&lh_ub) == real_isneg (&rh_ub));
2675 maybe_nan = false;
2676 // x * x never produces a new NAN and we only multiply the same
2677 // values, so the 0 * INF problematic cases never appear there.
2678 if (!is_square)
2680 // [+-0, +-0] * [+INF,+INF] (or [-INF,-INF] or swapped is a known NAN.
2681 if ((zero_p (lh_lb, lh_ub) && singleton_inf_p (rh_lb, rh_ub))
2682 || (zero_p (rh_lb, rh_ub) && singleton_inf_p (lh_lb, lh_ub)))
2684 real_nan (&lb, "", 0, TYPE_MODE (type));
2685 ub = lb;
2686 maybe_nan = true;
2687 return;
2690 // Otherwise, if one range includes zero and the other ends with +-INF,
2691 // it is a maybe NAN.
2692 if ((contains_zero_p (lh_lb, lh_ub)
2693 && (real_isinf (&rh_lb) || real_isinf (&rh_ub)))
2694 || (contains_zero_p (rh_lb, rh_ub)
2695 && (real_isinf (&lh_lb) || real_isinf (&lh_ub))))
2697 maybe_nan = true;
2699 int signbit_known = signbit_known_p (lh_lb, lh_ub, rh_lb, rh_ub);
2701 // If one of the ranges that includes INF is singleton
2702 // and the other range includes zero, the resulting
2703 // range is INF and NAN, because the 0 * INF boundary
2704 // case will be NAN, but already nextafter (0, 1) * INF
2705 // is INF.
2706 if (singleton_inf_p (lh_lb, lh_ub)
2707 || singleton_inf_p (rh_lb, rh_ub))
2708 return inf_range (lb, ub, signbit_known);
2710 // If one of the multiplicands must be zero, the resulting
2711 // range is +-0 and NAN.
2712 if (zero_p (lh_lb, lh_ub) || zero_p (rh_lb, rh_ub))
2713 return zero_range (lb, ub, signbit_known);
2715 // Otherwise one of the multiplicands could be
2716 // [0.0, nextafter (0.0, 1.0)] and the [DBL_MAX, INF]
2717 // or similarly with different signs. 0.0 * DBL_MAX
2718 // is still 0.0, nextafter (0.0, 1.0) * INF is still INF,
2719 // so if the signs are always the same or always different,
2720 // result is [+0.0, +INF] or [-INF, -0.0], otherwise VARYING.
2721 return zero_to_inf_range (lb, ub, signbit_known);
2725 REAL_VALUE_TYPE cp[8];
2726 // Do a cross-product. At this point none of the multiplications
2727 // should produce a NAN.
2728 frange_arithmetic (MULT_EXPR, type, cp[0], lh_lb, rh_lb, dconstninf);
2729 frange_arithmetic (MULT_EXPR, type, cp[4], lh_lb, rh_lb, dconstinf);
2730 if (is_square)
2732 // For x * x we can just do max (lh_lb * lh_lb, lh_ub * lh_ub)
2733 // as maximum and -0.0 as minimum if 0.0 is in the range,
2734 // otherwise min (lh_lb * lh_lb, lh_ub * lh_ub).
2735 // -0.0 rather than 0.0 because VREL_EQ doesn't prove that
2736 // x and y are bitwise equal, just that they compare equal.
2737 if (contains_zero_p (lh_lb, lh_ub))
2739 if (real_isneg (&lh_lb) == real_isneg (&lh_ub))
2740 cp[1] = dconst0;
2741 else
2742 cp[1] = dconstm0;
2744 else
2745 cp[1] = cp[0];
2746 cp[2] = cp[0];
2747 cp[5] = cp[4];
2748 cp[6] = cp[4];
2750 else
2752 frange_arithmetic (MULT_EXPR, type, cp[1], lh_lb, rh_ub, dconstninf);
2753 frange_arithmetic (MULT_EXPR, type, cp[5], lh_lb, rh_ub, dconstinf);
2754 frange_arithmetic (MULT_EXPR, type, cp[2], lh_ub, rh_lb, dconstninf);
2755 frange_arithmetic (MULT_EXPR, type, cp[6], lh_ub, rh_lb, dconstinf);
2757 frange_arithmetic (MULT_EXPR, type, cp[3], lh_ub, rh_ub, dconstninf);
2758 frange_arithmetic (MULT_EXPR, type, cp[7], lh_ub, rh_ub, dconstinf);
2760 find_range (lb, ub, cp);
2764 class foperator_div : public range_operator
2766 using range_operator::op1_range;
2767 using range_operator::op2_range;
2768 public:
2769 virtual bool op1_range (frange &r, tree type,
2770 const frange &lhs,
2771 const frange &op2,
2772 relation_trio = TRIO_VARYING) const final override
2774 if (lhs.undefined_p ())
2775 return false;
2776 frange wlhs = float_widen_lhs_range (type, lhs);
2777 bool ret = range_op_handler (MULT_EXPR).fold_range (r, type, wlhs, op2);
2778 if (!ret)
2779 return ret;
2780 if (wlhs.known_isnan () || op2.known_isnan () || op2.undefined_p ())
2781 return float_binary_op_range_finish (ret, r, type, wlhs);
2782 const REAL_VALUE_TYPE &lhs_lb = wlhs.lower_bound ();
2783 const REAL_VALUE_TYPE &lhs_ub = wlhs.upper_bound ();
2784 const REAL_VALUE_TYPE &op2_lb = op2.lower_bound ();
2785 const REAL_VALUE_TYPE &op2_ub = op2.upper_bound ();
2786 if ((contains_zero_p (lhs_lb, lhs_ub)
2787 && (real_isinf (&op2_lb) || real_isinf (&op2_ub)))
2788 || ((contains_zero_p (op2_lb, op2_ub))
2789 && (real_isinf (&lhs_lb) || real_isinf (&lhs_ub))))
2791 // If both lhs could be zero and op2 infinity or vice versa,
2792 // we don't know anything about op1 except maybe for the sign
2793 // and perhaps if it can be NAN or not.
2794 REAL_VALUE_TYPE lb, ub;
2795 int signbit_known = signbit_known_p (lhs_lb, lhs_ub, op2_lb, op2_ub);
2796 zero_to_inf_range (lb, ub, signbit_known);
2797 r.set (type, lb, ub);
2799 return float_binary_op_range_finish (ret, r, type, wlhs);
2801 virtual bool op2_range (frange &r, tree type,
2802 const frange &lhs,
2803 const frange &op1,
2804 relation_trio = TRIO_VARYING) const final override
2806 if (lhs.undefined_p ())
2807 return false;
2808 frange wlhs = float_widen_lhs_range (type, lhs);
2809 bool ret = fold_range (r, type, op1, wlhs);
2810 if (!ret)
2811 return ret;
2812 if (wlhs.known_isnan () || op1.known_isnan () || op1.undefined_p ())
2813 return float_binary_op_range_finish (ret, r, type, wlhs, true);
2814 const REAL_VALUE_TYPE &lhs_lb = wlhs.lower_bound ();
2815 const REAL_VALUE_TYPE &lhs_ub = wlhs.upper_bound ();
2816 const REAL_VALUE_TYPE &op1_lb = op1.lower_bound ();
2817 const REAL_VALUE_TYPE &op1_ub = op1.upper_bound ();
2818 if ((contains_zero_p (lhs_lb, lhs_ub) && contains_zero_p (op1_lb, op1_ub))
2819 || ((real_isinf (&lhs_lb) || real_isinf (&lhs_ub))
2820 && (real_isinf (&op1_lb) || real_isinf (&op1_ub))))
2822 // If both lhs and op1 could be zeros or both could be infinities,
2823 // we don't know anything about op2 except maybe for the sign
2824 // and perhaps if it can be NAN or not.
2825 REAL_VALUE_TYPE lb, ub;
2826 int signbit_known = signbit_known_p (lhs_lb, lhs_ub, op1_lb, op1_ub);
2827 zero_to_inf_range (lb, ub, signbit_known);
2828 r.set (type, lb, ub);
2830 return float_binary_op_range_finish (ret, r, type, wlhs, true);
2832 private:
2833 void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
2834 tree type,
2835 const REAL_VALUE_TYPE &lh_lb,
2836 const REAL_VALUE_TYPE &lh_ub,
2837 const REAL_VALUE_TYPE &rh_lb,
2838 const REAL_VALUE_TYPE &rh_ub,
2839 relation_kind) const final override
2841 // +-0.0 / +-0.0 or +-INF / +-INF is a known NAN.
2842 if ((zero_p (lh_lb, lh_ub) && zero_p (rh_lb, rh_ub))
2843 || (singleton_inf_p (lh_lb, lh_ub) && singleton_inf_p (rh_lb, rh_ub)))
2845 real_nan (&lb, "", 0, TYPE_MODE (type));
2846 ub = lb;
2847 maybe_nan = true;
2848 return;
2851 // If +-0.0 is in both ranges, it is a maybe NAN.
2852 if (contains_zero_p (lh_lb, lh_ub) && contains_zero_p (rh_lb, rh_ub))
2853 maybe_nan = true;
2854 // If +-INF is in both ranges, it is a maybe NAN.
2855 else if ((real_isinf (&lh_lb) || real_isinf (&lh_ub))
2856 && (real_isinf (&rh_lb) || real_isinf (&rh_ub)))
2857 maybe_nan = true;
2858 else
2859 maybe_nan = false;
2861 int signbit_known = signbit_known_p (lh_lb, lh_ub, rh_lb, rh_ub);
2863 // If dividend must be zero, the range is just +-0
2864 // (including if the divisor is +-INF).
2865 // If divisor must be +-INF, the range is just +-0
2866 // (including if the dividend is zero).
2867 if (zero_p (lh_lb, lh_ub) || singleton_inf_p (rh_lb, rh_ub))
2868 return zero_range (lb, ub, signbit_known);
2870 // If divisor must be zero, the range is just +-INF
2871 // (including if the dividend is +-INF).
2872 // If dividend must be +-INF, the range is just +-INF
2873 // (including if the dividend is zero).
2874 if (zero_p (rh_lb, rh_ub) || singleton_inf_p (lh_lb, lh_ub))
2875 return inf_range (lb, ub, signbit_known);
2877 // Otherwise if both operands may be zero, divisor could be
2878 // nextafter(0.0, +-1.0) and dividend +-0.0
2879 // in which case result is going to INF or vice versa and
2880 // result +0.0. So, all we can say for that case is if the
2881 // signs of divisor and dividend are always the same we have
2882 // [+0.0, +INF], if they are always different we have
2883 // [-INF, -0.0]. If they vary, VARYING.
2884 // If both may be +-INF, divisor could be INF and dividend FLT_MAX,
2885 // in which case result is going to INF or vice versa and
2886 // result +0.0. So, all we can say for that case is if the
2887 // signs of divisor and dividend are always the same we have
2888 // [+0.0, +INF], if they are always different we have
2889 // [-INF, -0.0]. If they vary, VARYING.
2890 if (maybe_nan)
2891 return zero_to_inf_range (lb, ub, signbit_known);
2893 REAL_VALUE_TYPE cp[8];
2894 // Do a cross-division. At this point none of the divisions should
2895 // produce a NAN.
2896 frange_arithmetic (RDIV_EXPR, type, cp[0], lh_lb, rh_lb, dconstninf);
2897 frange_arithmetic (RDIV_EXPR, type, cp[1], lh_lb, rh_ub, dconstninf);
2898 frange_arithmetic (RDIV_EXPR, type, cp[2], lh_ub, rh_lb, dconstninf);
2899 frange_arithmetic (RDIV_EXPR, type, cp[3], lh_ub, rh_ub, dconstninf);
2900 frange_arithmetic (RDIV_EXPR, type, cp[4], lh_lb, rh_lb, dconstinf);
2901 frange_arithmetic (RDIV_EXPR, type, cp[5], lh_lb, rh_ub, dconstinf);
2902 frange_arithmetic (RDIV_EXPR, type, cp[6], lh_ub, rh_lb, dconstinf);
2903 frange_arithmetic (RDIV_EXPR, type, cp[7], lh_ub, rh_ub, dconstinf);
2905 find_range (lb, ub, cp);
2907 // If divisor may be zero (but is not known to be only zero),
2908 // and dividend can't be zero, the range can go up to -INF or +INF
2909 // depending on the signs.
2910 if (contains_zero_p (rh_lb, rh_ub))
2912 if (signbit_known <= 0)
2913 real_inf (&lb, true);
2914 if (signbit_known >= 0)
2915 real_inf (&ub, false);
2918 } fop_div;
2921 // Initialize any float operators to the primary table
2923 void
2924 range_op_table::initialize_float_ops ()
2926 set (UNLE_EXPR, fop_unordered_le);
2927 set (UNLT_EXPR, fop_unordered_lt);
2928 set (UNGE_EXPR, fop_unordered_ge);
2929 set (UNGT_EXPR, fop_unordered_gt);
2930 set (UNEQ_EXPR, fop_unordered_equal);
2931 set (ORDERED_EXPR, fop_ordered);
2932 set (UNORDERED_EXPR, fop_unordered);
2933 set (LTGT_EXPR, fop_ltgt);
2934 set (RDIV_EXPR, fop_div);
2937 #if CHECKING_P
2938 #include "selftest.h"
2940 namespace selftest
2943 // Build an frange from string endpoints.
2945 static inline frange
2946 frange_float (const char *lb, const char *ub, tree type = float_type_node)
2948 REAL_VALUE_TYPE min, max;
2949 gcc_assert (real_from_string (&min, lb) == 0);
2950 gcc_assert (real_from_string (&max, ub) == 0);
2951 return frange (type, min, max);
2954 void
2955 range_op_float_tests ()
2957 frange r, r0, r1;
2958 frange trange (float_type_node);
2960 // negate([-5, +10]) => [-10, 5]
2961 r0 = frange_float ("-5", "10");
2962 range_op_handler (NEGATE_EXPR).fold_range (r, float_type_node, r0, trange);
2963 ASSERT_EQ (r, frange_float ("-10", "5"));
2965 // negate([0, 1] -NAN) => [-1, -0] +NAN
2966 r0 = frange_float ("0", "1");
2967 r0.update_nan (true);
2968 range_op_handler (NEGATE_EXPR).fold_range (r, float_type_node, r0, trange);
2969 r1 = frange_float ("-1", "-0");
2970 r1.update_nan (false);
2971 ASSERT_EQ (r, r1);
2973 // [-INF,+INF] + [-INF,+INF] could be a NAN.
2974 range_op_handler plus (PLUS_EXPR);
2975 r0.set_varying (float_type_node);
2976 r1.set_varying (float_type_node);
2977 r0.clear_nan ();
2978 r1.clear_nan ();
2979 plus.fold_range (r, float_type_node, r0, r1);
2980 if (HONOR_NANS (float_type_node))
2981 ASSERT_TRUE (r.maybe_isnan ());
2984 } // namespace selftest
2986 #endif // CHECKING_P