public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] [PR tree-optimization/107490] Handle NANs in op[12]_range.
@ 2022-11-01 18:25 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-11-01 18:25 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-01 18:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 18:25 [COMMITTED] [PR tree-optimization/107490] Handle NANs in op[12]_range 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).