public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Handle > INF and < INF correctly in range-op-float.cc
@ 2022-09-06  7:29 Aldy Hernandez
  2022-09-06  7:35 ` Jakub Jelinek
  0 siblings, 1 reply; 11+ messages in thread
From: Aldy Hernandez @ 2022-09-06  7:29 UTC (permalink / raw)
  To: GCC patches; +Cc: Richard Biener, Jakub Jelinek, Andrew MacLeod, Aldy Hernandez

The gfortran.dg/minlocval*.f90 tests are generating conditionals past
the infinities.  For example:

	if (x <= +Inf)
	  foo (x);
	else
	  bar (x);

It seems to me that the only possible value for x on the false side is
either NAN or undefined (for !HONOR_NANS).

Is this correct, or is there some other FP nuance I'm unaware of?

gcc/ChangeLog:

	* range-op-float.cc (build_lt): Handle < -INF.
	(build_gt): Handle > +INF.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/vrp-float-inf-1.c: New test.
---
 gcc/range-op-float.cc                          | 18 ++++++++++++++++++
 .../gcc.dg/tree-ssa/vrp-float-inf-1.c          | 15 +++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 050f07a9867..4515bbf0b7e 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -235,6 +235,15 @@ build_le (frange &r, tree type, const REAL_VALUE_TYPE &val)
 static void
 build_lt (frange &r, tree type, const REAL_VALUE_TYPE &val)
 {
+  if (real_isinf (&val, 1))
+    {
+      if (HONOR_NANS (type))
+	frange_set_nan (r, type);
+      else
+	r.set_undefined ();
+      return;
+    }
+
   // Hijack LE because we only support closed intervals.
   build_le (r, type, val);
 }
@@ -252,6 +261,15 @@ build_ge (frange &r, tree type, const REAL_VALUE_TYPE &val)
 static void
 build_gt (frange &r, tree type, const REAL_VALUE_TYPE &val)
 {
+  if (real_isinf (&val, 0))
+    {
+      if (HONOR_NANS (type))
+	frange_set_nan (r, type);
+      else
+	r.set_undefined ();
+      return;
+    }
+
   // Hijack GE because we only support closed intervals.
   build_ge (r, type, val);
 }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c
new file mode 100644
index 00000000000..1d21cce41e6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-inf-1.c
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-evrp-details" }
+
+void foo ();
+void bar (double);
+
+void funky(double f, double g)
+{
+  if (f <= __builtin_inf ())
+    foo ();
+  else
+    bar (f);
+}
+
+// { dg-final { scan-tree-dump-not " Inf,  Inf" "evrp" } }
-- 
2.37.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-09-06 12:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-06  7:29 [PATCH] Handle > INF and < INF correctly in range-op-float.cc Aldy Hernandez
2022-09-06  7:35 ` Jakub Jelinek
2022-09-06  7:40   ` Aldy Hernandez
2022-09-06  7:44     ` Jakub Jelinek
2022-09-06  7:49       ` Aldy Hernandez
2022-09-06  7:59         ` Jakub Jelinek
2022-09-06 11:47           ` Aldy Hernandez
2022-09-06 12:06             ` Jakub Jelinek
2022-09-06 12:17               ` Richard Biener
2022-09-06 12:32                 ` Aldy Hernandez
2022-09-06 12:38               ` Koning, Paul

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).