public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9126] i386: Fix __builtin_floor with FE_DOWNWARD rounding direction [PR96793]
@ 2020-12-23 8:10 Uros Bizjak
0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2020-12-23 8:10 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c40b640ebcef1aae78eaca56e04d204dda9e4cad
commit r9-9126-gc40b640ebcef1aae78eaca56e04d204dda9e4cad
Author: Uros Bizjak <ubizjak@gmail.com>
Date: Wed Dec 23 09:09:29 2020 +0100
i386: Fix __builtin_floor with FE_DOWNWARD rounding direction [PR96793]
x86_expand_floorceil expander uses x86_sse_copysign_to_positive, which
is unable to change the sign from - to +. When FE_DOWNWARD rounding
direction is in effect, the expanded sequence that involves subtraction
can trigger x - x = -0.0 special rule. x86_sse_copysign_to_positive
fails to change the sign of the intermediate value, assumed to always
be positive, back to positive.
The patch adds one extra fabs that strips the sign from the intermediate
value when flag_rounding_math is in effect.
2020-12-22 Uroš Bizjak <ubizjak@gmail.com>
gcc/
PR target/96793
* config/i386/i386.c (ix86_expand_floorceil):
Remove the sign of the intermediate value for flag_rounding_math.
(ix86_expand_floorceildf_32): Ditto.
gcc/testsuite/
PR target/96793
* gcc.target/i386/pr96793.c: New test.
Diff:
---
gcc/config/i386/i386.c | 25 ++++++++++++++++++++-----
gcc/testsuite/gcc.target/i386/pr96793.c | 28 ++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index e8982c507e4..e0f924e50b2 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -45511,12 +45511,14 @@ ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
return x;
xa = xa + TWO52 - TWO52;
x2 = copysign (xa, x);
+
Compensate. Floor:
if (x2 > x)
x2 -= 1;
Compensate. Ceil:
if (x2 < x)
x2 += 1;
+
if (HONOR_SIGNED_ZEROS (mode))
x2 = copysign (x2, x);
return x2;
@@ -45553,8 +45555,14 @@ ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
emit_insn (gen_rtx_SET (tmp, gen_rtx_AND (mode, one, tmp)));
tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
- if (!do_floor && HONOR_SIGNED_ZEROS (mode))
- ix86_sse_copysign_to_positive (tmp, tmp, res, mask);
+ if (HONOR_SIGNED_ZEROS (mode))
+ {
+ /* Remove the sign with FE_DOWNWARD, where x - x = -0.0. */
+ if (do_floor && flag_rounding_math)
+ tmp = ix86_expand_sse_fabs (tmp, NULL);
+
+ ix86_sse_copysign_to_positive (tmp, tmp, res, mask);
+ }
emit_move_insn (res, tmp);
emit_label (label);
@@ -45573,12 +45581,14 @@ ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
if (!isless (xa, TWO52))
return x;
x2 = (double)(long)x;
+
Compensate. Floor:
if (x2 > x)
x2 -= 1;
Compensate. Ceil:
if (x2 < x)
x2 += 1;
+
if (HONOR_SIGNED_ZEROS (mode))
return copysign (x2, x);
return x2;
@@ -45613,10 +45623,15 @@ ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
emit_insn (gen_rtx_SET (tmp, gen_rtx_AND (mode, one, tmp)));
tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
- emit_move_insn (res, tmp);
-
if (HONOR_SIGNED_ZEROS (mode))
- ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
+ {
+ /* Remove the sign with FE_DOWNWARD, where x - x = -0.0. */
+ if (do_floor && flag_rounding_math)
+ tmp = ix86_expand_sse_fabs (tmp, NULL);
+
+ ix86_sse_copysign_to_positive (tmp, tmp, res, mask);
+ }
+ emit_move_insn (res, tmp);
emit_label (label);
LABEL_NUSES (label) = 1;
diff --git a/gcc/testsuite/gcc.target/i386/pr96793.c b/gcc/testsuite/gcc.target/i386/pr96793.c
new file mode 100644
index 00000000000..4a96478e31e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr96793.c
@@ -0,0 +1,28 @@
+/* PR target/96793 */
+/* { dg-do run { target sse2_runtime } } */
+/* { dg-require-effective-target fenv } */
+/* { dg-options "-O2 -frounding-math -msse2 -mno-sse4 -mfpmath=sse" } */
+
+#include <fenv.h>
+
+double
+__attribute__((noinline))
+test (double value)
+{
+ return __builtin_floor (value);
+}
+
+int
+main ()
+{
+ double result;
+
+ fesetround (FE_DOWNWARD);
+
+ result = test (0.25);
+
+ if (__builtin_signbit (result) != 0)
+ __builtin_abort ();
+
+ return 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-23 8:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 8:10 [gcc r9-9126] i386: Fix __builtin_floor with FE_DOWNWARD rounding direction [PR96793] 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).