public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [ranger] x == -0.0 does not mean we can replace x with -0.0
@ 2022-08-26 15:46 Aldy Hernandez
  2022-08-26 16:40 ` Jakub Jelinek
  0 siblings, 1 reply; 14+ messages in thread
From: Aldy Hernandez @ 2022-08-26 15:46 UTC (permalink / raw)
  To: GCC patches; +Cc: Jakub Jelinek, Andrew MacLeod, Aldy Hernandez

On the true side of x == -0.0, we can't just blindly value propagate
the -0.0 into every use of x because x could be +0.0 (or vice versa).

With this change, we only allow the transformation if
!HONOR_SIGNED_ZEROS or if the range is known not to contain 0.

Will commit after tests complete.

gcc/ChangeLog:

	* range-op-float.cc (foperator_equal::op1_range): Do not blindly
	copy op2 range when honoring signed zeros.
---
 gcc/range-op-float.cc | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index ad2fae578d2..ff9fe312acf 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -252,8 +252,21 @@ foperator_equal::op1_range (frange &r, tree type,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      // If it's true, the result is the same as OP2.
-      r = op2;
+      if (HONOR_SIGNED_ZEROS (type)
+	  && op2.contains_p (build_zero_cst (type)))
+	{
+	  // With signed zeros, x == -0.0 does not mean we can replace
+	  // x with -0.0, because x may be either +0.0 or -0.0.
+	  r.set_varying (type);
+	}
+      else
+	{
+	  // If it's true, the result is the same as OP2.
+	  //
+	  // If the range does not actually contain zeros, this should
+	  // always be OK.
+	  r = op2;
+	}
       // The TRUE side of op1 == op2 implies op1 is !NAN.
       r.set_nan (fp_prop::NO);
       break;
-- 
2.37.1


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

end of thread, other threads:[~2022-08-31 10:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 15:46 [PATCH] [ranger] x == -0.0 does not mean we can replace x with -0.0 Aldy Hernandez
2022-08-26 16:40 ` Jakub Jelinek
2022-08-29 13:13   ` Aldy Hernandez
2022-08-29 13:21     ` Jakub Jelinek
2022-08-29 13:31       ` Aldy Hernandez
2022-08-29 14:20         ` Jeff Law
2022-08-29 14:26           ` Aldy Hernandez
2022-08-29 15:08             ` Jeff Law
2022-08-29 15:13               ` Toon Moene
2022-08-29 17:07                 ` Jeff Law
2022-08-29 17:37                   ` Koning, Paul
2022-08-29 19:04                   ` Toon Moene
2022-08-29 15:29               ` Aldy Hernandez
2022-08-31 10:08       ` 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).