From e98e63404c6b3057ac0f0ff4fe871cd19a1aacb4 Mon Sep 17 00:00:00 2001
From: Segher Boessenkool <segher@kernel.crashing.org>
Date: Wed, 17 May 2017 23:57:23 +0200
Subject: [PATCH] Fix comparison of decimal float zeroes (PR80692)

Decimal float negative zero should compare equal to positive zero.
Decimal float zeroes are encoded as value class "normal" (in real.c);
they need to be handled specially, but in this one case that does not
yet happen.  This fixes it.


	PR middle-end/80692
	* real.c (do_compare): Give decimal_do_compare preference over
	comparing just the signs.

gcc/testsuite/
	PR middle-end/80692
	* gcc.c-torture/execute/pr80692.c: New testcase.

From-SVN: r248174
---
 gcc/ChangeLog                                 |  6 ++++++
 gcc/real.c                                    |  6 +++---
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/gcc.c-torture/execute/pr80692.c | 13 +++++++++++++
 4 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr80692.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 068ddd90d1e7..f9a143068a0f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-17  Segher Boessenkool  <segher@kernel.crashing.org>
+
+	PR middle-end/80692
+	* real.c (do_compare): Give decimal_do_compare preference over
+	comparing just the signs.
+
 2017-05-17  Uros Bizjak  <ubizjak@gmail.com>
 
 	* doc/md.texi (Canonicalization of Instructions): Describe the
diff --git a/gcc/real.c b/gcc/real.c
index 97452a9701ed..a5671b2865bd 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -960,12 +960,12 @@ do_compare (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b,
       gcc_unreachable ();
     }
 
-  if (a->sign != b->sign)
-    return -a->sign - -b->sign;
-
   if (a->decimal || b->decimal)
     return decimal_do_compare (a, b, nan_result);
 
+  if (a->sign != b->sign)
+    return -a->sign - -b->sign;
+
   if (REAL_EXP (a) > REAL_EXP (b))
     ret = 1;
   else if (REAL_EXP (a) < REAL_EXP (b))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9549f609cf04..7b38a5233f99 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-17  Segher Boessenkool  <segher@kernel.crashing.org>
+
+	PR middle-end/80692
+	* gcc.c-torture/execute/pr80692.c: New testcase.
+
 2017-05-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
 	PR libgfortran/80741
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr80692.c b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
new file mode 100644
index 000000000000..e653c71c9130
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
@@ -0,0 +1,13 @@
+/* { dg-require-effective-target dfp } */
+
+int main () {
+	_Decimal64 d64 = -0.DD;
+
+	if (d64 != 0.DD)
+		__builtin_abort ();
+
+	if (d64 != -0.DD)
+		__builtin_abort ();
+
+	return 0;
+}
-- 
GitLab