* [COMMITTED] Return non-legacy ranges in range.h.
@ 2022-10-10 12:49 Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side) Aldy Hernandez
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-10 12:49 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
int_range<1> is a legacy range (think anti ranges, legacy VRP, etc).
There is a penalty for converting anything built with <1> to
non-legacy. Since most of the uses of these functions are now ranger,
we can save a miniscule amount of time by converting them to
non-legacy.
gcc/ChangeLog:
* range.h (range_true): Return int_range<2>.
(range_false): Same.
(range_true_and_false): Same.
---
gcc/range.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/gcc/range.h b/gcc/range.h
index 5c70c66566c..8138d6f5515 100644
--- a/gcc/range.h
+++ b/gcc/range.h
@@ -32,7 +32,7 @@ static inline int_range<1>
range_true (tree type)
{
unsigned prec = TYPE_PRECISION (type);
- return int_range<1> (type, wi::one (prec), wi::one (prec));
+ return int_range<2> (type, wi::one (prec), wi::one (prec));
}
// Return an irange instance that is a boolean FALSE.
@@ -41,7 +41,7 @@ static inline int_range<1>
range_false (tree type)
{
unsigned prec = TYPE_PRECISION (type);
- return int_range<1> (type, wi::zero (prec), wi::zero (prec));
+ return int_range<2> (type, wi::zero (prec), wi::zero (prec));
}
// Return an irange that covers both true and false.
@@ -50,7 +50,7 @@ static inline int_range<1>
range_true_and_false (tree type)
{
unsigned prec = TYPE_PRECISION (type);
- return int_range<1> (type, wi::zero (prec), wi::one (prec));
+ return int_range<2> (type, wi::zero (prec), wi::one (prec));
}
#endif // GCC_RANGE_H
--
2.37.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [COMMITTED] x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side).
2022-10-10 12:49 [COMMITTED] Return non-legacy ranges in range.h Aldy Hernandez
@ 2022-10-10 12:49 ` Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] The true side of x != x should set NAN Aldy Hernandez
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-10 12:49 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
gcc/ChangeLog:
* range-op-float.cc (foperator_unordered::op1_range): Set NAN when
operands are equal and result is TRUE.
---
gcc/range-op-float.cc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 68578aa6fe7..91833d3f855 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1026,23 +1026,27 @@ bool
foperator_unordered::op1_range (frange &r, tree type,
const irange &lhs,
const frange &op2,
- relation_kind) const
+ relation_kind rel) const
{
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
+ if (rel == VREL_EQ)
+ r.set_nan (type);
// Since at least one operand must be NAN, if one of them is
// not, the other must be.
- if (!op2.maybe_isnan ())
+ else if (!op2.maybe_isnan ())
r.set_nan (type);
else
r.set_varying (type);
break;
case BRS_FALSE:
+ if (rel == VREL_EQ)
+ r.clear_nan ();
// A false UNORDERED means both operands are !NAN, so it's
// impossible for op2 to be a NAN.
- if (op2.known_isnan ())
+ else if (op2.known_isnan ())
r.set_undefined ();
else
{
--
2.37.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [COMMITTED] The true side of x != x should set NAN.
2022-10-10 12:49 [COMMITTED] Return non-legacy ranges in range.h Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side) Aldy Hernandez
@ 2022-10-10 12:49 ` Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] Add frange::maybe_isnan (bool sign) Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] Make range-op-float entries public Aldy Hernandez
3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-10 12:49 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
gcc/ChangeLog:
* range-op-float.cc (foperator_not_equal::op1_range): Set NAN on
TRUE side for x != x.
---
gcc/range-op-float.cc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 91833d3f855..5ffe38da53a 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -497,14 +497,17 @@ bool
foperator_not_equal::op1_range (frange &r, tree type,
const irange &lhs,
const frange &op2,
- relation_kind) const
+ relation_kind rel) const
{
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
+ // The TRUE side of op1 != op1 implies op1 is NAN.
+ if (rel == VREL_EQ)
+ r.set_nan (type);
// If the result is true, the only time we know anything is if
// OP2 is a constant.
- if (op2.singleton_p ())
+ else if (op2.singleton_p ())
{
// This is correct even if op1 is NAN, because the following
// range would be ~[tmp, tmp] with the NAN property set to
--
2.37.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [COMMITTED] Add frange::maybe_isnan (bool sign).
2022-10-10 12:49 [COMMITTED] Return non-legacy ranges in range.h Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side) Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] The true side of x != x should set NAN Aldy Hernandez
@ 2022-10-10 12:49 ` Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] Make range-op-float entries public Aldy Hernandez
3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-10 12:49 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
It is useful to know if there's the possiblity of a NAN with a given
sign. This is to complement maybe_isnan(void) which returns TRUE for a
NAN of any sign.
A follow-up patch implementing ABS will make use of this.
gcc/ChangeLog:
* value-range.h (frange::maybe_isnan): New.
---
gcc/value-range.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 484f911bd90..07a2067898c 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -323,6 +323,7 @@ public:
bool known_isnan () const;
bool known_isinf () const;
bool maybe_isnan () const;
+ bool maybe_isnan (bool sign) const;
bool maybe_isinf () const;
bool signbit_p (bool &signbit) const;
private:
@@ -1295,6 +1296,18 @@ frange::maybe_isnan () const
return m_pos_nan || m_neg_nan;
}
+// Return TRUE if range is possibly a NAN with SIGN.
+
+inline bool
+frange::maybe_isnan (bool sign) const
+{
+ if (undefined_p ())
+ return false;
+ if (sign)
+ return m_neg_nan;
+ return m_pos_nan;
+}
+
// Return TRUE if range is a +NAN or -NAN.
inline bool
--
2.37.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [COMMITTED] Make range-op-float entries public.
2022-10-10 12:49 [COMMITTED] Return non-legacy ranges in range.h Aldy Hernandez
` (2 preceding siblings ...)
2022-10-10 12:49 ` [COMMITTED] Add frange::maybe_isnan (bool sign) Aldy Hernandez
@ 2022-10-10 12:49 ` Aldy Hernandez
3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-10 12:49 UTC (permalink / raw)
To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez
gcc/ChangeLog:
* range-op-float.cc (class foperator_identity): Make members public.
(class foperator_equal): Same.
(class foperator_not_equal): Same.
(class foperator_lt): Same.
(class foperator_le): Same.
(class foperator_gt): Same.
(class foperator_ge): Same.
(class foperator_unordered): Same.
(class foperator_ordered): Same.
---
gcc/range-op-float.cc | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 5ffe38da53a..3cf117d8931 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -315,7 +315,7 @@ class foperator_identity : public range_operator_float
{
using range_operator_float::fold_range;
using range_operator_float::op1_range;
-
+public:
bool fold_range (frange &r, tree type ATTRIBUTE_UNUSED,
const frange &op1, const frange &op2 ATTRIBUTE_UNUSED,
relation_kind) const final override
@@ -338,7 +338,7 @@ class foperator_equal : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
+public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
relation_kind rel) const final override;
@@ -444,7 +444,7 @@ class foperator_not_equal : public range_operator_float
{
using range_operator_float::fold_range;
using range_operator_float::op1_range;
-
+public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
relation_kind rel) const final override;
@@ -545,7 +545,7 @@ class foperator_lt : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
+public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
relation_kind rel) const final override;
@@ -660,7 +660,7 @@ class foperator_le : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
+public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
relation_kind rel) const final override;
@@ -767,7 +767,7 @@ class foperator_gt : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
+public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
relation_kind rel) const final override;
@@ -882,7 +882,7 @@ class foperator_ge : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
+public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
relation_kind rel) const final override;
@@ -993,7 +993,6 @@ class foperator_unordered : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
@@ -1071,7 +1070,6 @@ class foperator_ordered : public range_operator_float
using range_operator_float::fold_range;
using range_operator_float::op1_range;
using range_operator_float::op2_range;
-
public:
bool fold_range (irange &r, tree type,
const frange &op1, const frange &op2,
--
2.37.3
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-10 12:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 12:49 [COMMITTED] Return non-legacy ranges in range.h Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side) Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] The true side of x != x should set NAN Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] Add frange::maybe_isnan (bool sign) Aldy Hernandez
2022-10-10 12:49 ` [COMMITTED] Make range-op-float entries public Aldy Hernandez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).