From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] [PR tree-optimization/107490] Handle NANs in op[12]_range.
Date: Tue, 1 Nov 2022 19:25:37 +0100 [thread overview]
Message-ID: <20221101182537.50407-1-aldyh@redhat.com> (raw)
None of the build_<OP> functions in range-op handle NANs. This is by
design in order to force us to handle NANs specially, because
"x relop NAN" makes no sense. This patch fixes a handful of
op[12]_range entries that weren't handling NANs.
PR tree-optimization/107490
gcc/ChangeLog:
* range-op-float.cc (foperator_unordered_lt::op1_range): Handle
NANs.
(foperator_unordered_lt::op2_range): Same.
(foperator_unordered_le::op1_range): Same.
(foperator_unordered_le::op2_range): Same.
(foperator_unordered_gt::op1_range): Same.
(foperator_unordered_gt::op2_range): Same.
(foperator_unordered_ge::op1_range): Same.
(foperator_unordered_ge::op2_range): Same.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr107490.c: New test.
---
gcc/range-op-float.cc | 40 +++++++++++++++++++-----
gcc/testsuite/gcc.dg/tree-ssa/pr107490.c | 28 +++++++++++++++++
2 files changed, 60 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107490.c
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 04208c88dd1..a1f372997bf 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1332,7 +1332,10 @@ foperator_unordered_lt::op1_range (frange &r, tree type,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_lt (r, type, op2);
+ if (op2.known_isnan ())
+ r.set_varying (type);
+ else
+ build_lt (r, type, op2);
break;
case BRS_FALSE:
@@ -1359,7 +1362,10 @@ foperator_unordered_lt::op2_range (frange &r, tree type,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_gt (r, type, op1);
+ if (op1.known_isnan ())
+ r.set_varying (type);
+ else
+ build_gt (r, type, op1);
break;
case BRS_FALSE:
@@ -1420,7 +1426,10 @@ foperator_unordered_le::op1_range (frange &r, tree type,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_le (r, type, op2);
+ if (op2.known_isnan ())
+ r.set_varying (type);
+ else
+ build_le (r, type, op2);
break;
case BRS_FALSE:
@@ -1448,7 +1457,10 @@ foperator_unordered_le::op2_range (frange &r,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_ge (r, type, op1);
+ if (op1.known_isnan ())
+ r.set_varying (type);
+ else
+ build_ge (r, type, op1);
break;
case BRS_FALSE:
@@ -1511,7 +1523,10 @@ foperator_unordered_gt::op1_range (frange &r,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_gt (r, type, op2);
+ if (op2.known_isnan ())
+ r.set_varying (type);
+ else
+ build_gt (r, type, op2);
break;
case BRS_FALSE:
@@ -1539,7 +1554,10 @@ foperator_unordered_gt::op2_range (frange &r,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_lt (r, type, op1);
+ if (op1.known_isnan ())
+ r.set_varying (type);
+ else
+ build_lt (r, type, op1);
break;
case BRS_FALSE:
@@ -1602,7 +1620,10 @@ foperator_unordered_ge::op1_range (frange &r,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_ge (r, type, op2);
+ if (op2.known_isnan ())
+ r.set_varying (type);
+ else
+ build_ge (r, type, op2);
break;
case BRS_FALSE:
@@ -1629,7 +1650,10 @@ foperator_unordered_ge::op2_range (frange &r, tree type,
switch (get_bool_state (r, lhs, type))
{
case BRS_TRUE:
- build_le (r, type, op1);
+ if (op1.known_isnan ())
+ r.set_varying (type);
+ else
+ build_le (r, type, op1);
break;
case BRS_FALSE:
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107490.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107490.c
new file mode 100644
index 00000000000..87c7f0aacdd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107490.c
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-options "-Os -fno-trapping-math -w" }
+
+extern void abort (void);
+
+#define MIN2(a,b) (((a)<(b)) ? (a) : (b))
+#define MAX2(a,b) (((a)>(b)) ? (a) : (b))
+
+double p[2] = { 4.f, 5.f };
+
+int main()
+{
+ long j;
+ double R, n, x;
+ n = 1.e300f;
+ x = -1.e300f;
+ for( j=0; j < 2; j++ )
+ {
+ x = MAX2(x,p[j]);
+ n = MIN2(n,p[j]);
+ }
+ R = x-n;
+
+ if( R < 0.1 )
+ abort ();
+
+ return 0;
+}
--
2.38.1
reply other threads:[~2022-11-01 18:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221101182537.50407-1-aldyh@redhat.com \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).