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

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.
This commit is contained in:
Aldy Hernandez 2022-09-12 13:04:02 +02:00
parent 71cd6a0430
commit 06b30eecdd

View file

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