public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-61] i386: Fix unsigned int -> double conversion on i386 w/ -mfpmath=sse [PR100119]
@ 2021-04-22 14:32 Uros Bizjak
  0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2021-04-22 14:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0cda606d08d6196b76524c7b6ad51d87fed0d54b

commit r12-61-g0cda606d08d6196b76524c7b6ad51d87fed0d54b
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Thu Apr 22 16:30:38 2021 +0200

    i386: Fix unsigned int -> double conversion on i386 w/ -mfpmath=sse [PR100119]
    
    2021-04-22  Uroš Bizjak  <ubizjak@gmail.com>
    
    gcc/
            PR target/100119
            * config/i386/i386-expand.c (ix86_expand_convert_uns_sidf_sse):
            Remove the sign with FE_DOWNWARD, where x - x = -0.0.
    
    gcc/testsuite/
    
            PR target/100119
            * gcc.target/i386/pr100119.c: New test.

Diff:
---
 gcc/config/i386/i386-expand.c            |  7 +++++++
 gcc/testsuite/gcc.target/i386/pr100119.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 166c23ddb4d..516440eb5c1 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -1550,6 +1550,8 @@ ix86_expand_convert_uns_sixf_sse (rtx, rtx)
   gcc_unreachable ();
 }
 
+static rtx ix86_expand_sse_fabs (rtx op0, rtx *smask);
+
 /* Convert an unsigned SImode value into a DFmode.  Only currently used
    for SSE, but applicable anywhere.  */
 
@@ -1569,6 +1571,11 @@ ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
   x = const_double_from_real_value (TWO31r, DFmode);
 
   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
+
+  /* Remove the sign with FE_DOWNWARD, where x - x = -0.0.  */
+  if (HONOR_SIGNED_ZEROS (DFmode) && flag_rounding_math)
+    x = ix86_expand_sse_fabs (x, NULL);
+
   if (x != target)
     emit_move_insn (target, x);
 }
diff --git a/gcc/testsuite/gcc.target/i386/pr100119.c b/gcc/testsuite/gcc.target/i386/pr100119.c
new file mode 100644
index 00000000000..be9472eb939
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr100119.c
@@ -0,0 +1,28 @@
+/* PR target/100119 */
+/* { dg-do run { target sse2_runtime } } */
+/* { dg-require-effective-target fenv } */
+/* { dg-options "-O2 -frounding-math -msse2 -mno-avx512f -mfpmath=sse" } */
+
+#include <fenv.h>
+
+double
+__attribute__((noinline))
+test (unsigned int x)
+{
+  return x;
+}
+
+int
+main ()
+{
+  double result;
+
+  fesetround (FE_DOWNWARD);
+
+  result = test (0);
+
+  if (__builtin_signbit (result) != 0)
+    __builtin_abort ();
+
+  return 0;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-22 14:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 14:32 [gcc r12-61] i386: Fix unsigned int -> double conversion on i386 w/ -mfpmath=sse [PR100119] Uros Bizjak

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