public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3598] [PR tree-optimization/107490] Handle NANs in op[12]_range.
Date: Tue,  1 Nov 2022 18:24:31 +0000 (GMT)	[thread overview]
Message-ID: <20221101182440.265E1385840E@sourceware.org> (raw)

https://gcc.gnu.org/g:bdf0018519c39931fdcc7aeffe9e87ba756894d7

commit r13-3598-gbdf0018519c39931fdcc7aeffe9e87ba756894d7
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Nov 1 17:27:39 2022 +0100

    [PR tree-optimization/107490] Handle NANs in op[12]_range.
    
    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.

Diff:
---
 gcc/range-op-float.cc                    | 40 +++++++++++++++++++++++++-------
 gcc/testsuite/gcc.dg/tree-ssa/pr107490.c | 28 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 8 deletions(-)

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;
+}

                 reply	other threads:[~2022-11-01 18:24 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=20221101182440.265E1385840E@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@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).