[COMMITTED,PR106967] Set known NANs to undefined for flag_finite_math_only.

Message ID 20220921113039.2173181-1-aldyh@redhat.com
State Committed
Commit dc829c7613ddf562d1aecaf22eda965e87108ac8
Headers
Series [COMMITTED,PR106967] Set known NANs to undefined for flag_finite_math_only. |

Commit Message

Aldy Hernandez Sept. 21, 2022, 11:30 a.m. UTC
  Richard, this is what you suggested.  Thanks.

Explicit NANs in the IL can be treated as undefined for
flag_finite_math_only.  This causes all the right things to happen wrt
threading, folding, etc.  It also saves us special casing throughout.

It occurs to me that we should do something similar for infinities for
-ffinite-math-only.  That is, drop them to the min/max representable
numbers, and adjust everything (including VARYING endpoints)
accordingly.  Furthermore, we should saturate to min/max representable
in the setter, so (upcoming) binary operators don't have to worry about
going over min/max.

Sigh...floating point... the gift that keeps on giving.

gcc/ChangeLog:

	* value-range.cc (frange::set): Set known NANs to undefined for
	flag_finite_math_only.
---
 gcc/value-range.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 505eb9211a7..7e8028eced2 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -313,8 +313,13 @@  frange::set (tree min, tree max, value_range_kind kind)
       gcc_checking_assert (real_identical (TREE_REAL_CST_PTR (min),
 					   TREE_REAL_CST_PTR (max)));
       tree type = TREE_TYPE (min);
-      bool sign = real_isneg (TREE_REAL_CST_PTR (min));
-      set_nan (type, sign);
+      if (HONOR_NANS (type))
+	{
+	  bool sign = real_isneg (TREE_REAL_CST_PTR (min));
+	  set_nan (type, sign);
+	}
+      else
+	set_undefined ();
       return;
     }