diff mbox series

[COMMITTED] frange::set_signbit: Avoid changing sign when already in the correct sign.

Message ID 20220912130711.484083-1-aldyh@redhat.com
State New
Headers show
Series [COMMITTED] frange::set_signbit: Avoid changing sign when already in the correct sign. | expand

Commit Message

Aldy Hernandez Sept. 12, 2022, 1:07 p.m. UTC
We should avoid pessimizing the signbit when it's already correct.  In
this particular case we were trying to change the signbit to "unknown",
when it was obviously negative.

This test is actually slated for removal with my upcoming revamp of the
signbit and NAN tracking, per the conversations regarding tristate.  The
signbit will be removed in favor of keeping track of it in the range
itself, and NAN will just be a pair of boolean flags.  However, I don't
plan to disturb the tree until after Cauldron.

Tested on x86-64 Linux including mpfr tests.  Also tested selftests with
-ffinite-math-only on x86-64 as well as on a cross to pdp11-aout.

gcc/ChangeLog:

	* value-range.cc (frange::set_signbit): Avoid changing sign when
	already in the correct sign.
---
 gcc/value-range.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index adcaaa2a69a..6f0609959b3 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -316,9 +316,13 @@  frange::set_signbit (fp_prop::kind k)
   // Ignore sign changes when they're set correctly.
   if (!maybe_nan ())
     {
-      if (real_less (&m_max, &dconst0))
+      // It's negative and we're trying to make it negative or varying.
+      if (real_less (&m_max, &dconst0) && (k == fp_prop::YES
+					   || k == fp_prop::VARYING))
 	return;
-      if (real_less (&dconst0, &m_min))
+      // It's positive and we're trying to make it positive or varying.
+      if (real_less (&dconst0, &m_min) && (k == fp_prop::NO
+					   || k == fp_prop::VARYING))
 	return;
     }
   // Adjust the range depending on the sign bit.