public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Uros Bizjak <uros@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r8-10700] i386: Fix __builtin_rint with FE_DOWNWARD rounding direction [PR96793] Date: Mon, 28 Dec 2020 23:18:13 +0000 (GMT) [thread overview] Message-ID: <20201228231813.DBF4B3851C04@sourceware.org> (raw) https://gcc.gnu.org/g:e64a8d36074ca15b2a3fb453c9abbf9a884e9668 commit r8-10700-ge64a8d36074ca15b2a3fb453c9abbf9a884e9668 Author: Uros Bizjak <ubizjak@gmail.com> Date: Tue Dec 29 00:17:24 2020 +0100 i386: Fix __builtin_rint with FE_DOWNWARD rounding direction [PR96793] x86_expand_rint 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-28 Uroš Bizjak <ubizjak@gmail.com> gcc/ PR target/96793 * config/i386/i386.c (ix86_expand_rint): Remove the sign of the intermediate value for flag_rounding_math. gcc/testsuite/ PR target/96793 * gcc.target/i386/pr96793-2.c: New test. Diff: --- gcc/config/i386/i386.c | 16 +++++++++------- gcc/testsuite/gcc.target/i386/pr96793-2.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 5ac453b9fed..d97d5c0f0fe 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -45613,7 +45613,7 @@ ix86_expand_rint (rtx operand0, rtx operand1) return copysign (xa, operand1); */ machine_mode mode = GET_MODE (operand0); - rtx res, xa, TWO52, two52, mask; + rtx res, xa, TWO52, mask; rtx_code_label *label; res = gen_reg_rtx (mode); @@ -45626,16 +45626,18 @@ ix86_expand_rint (rtx operand0, rtx operand1) TWO52 = ix86_gen_TWO52 (mode); label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false); - two52 = TWO52; if (flag_rounding_math) { - two52 = gen_reg_rtx (mode); - ix86_sse_copysign_to_positive (two52, TWO52, res, mask); + ix86_sse_copysign_to_positive (TWO52, TWO52, res, mask); xa = res; } - xa = expand_simple_binop (mode, PLUS, xa, two52, NULL_RTX, 0, OPTAB_DIRECT); - xa = expand_simple_binop (mode, MINUS, xa, two52, xa, 0, OPTAB_DIRECT); + xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT); + xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT); + + /* Remove the sign with FE_DOWNWARD, where x - x = -0.0. */ + if (HONOR_SIGNED_ZEROS (mode) && flag_rounding_math) + xa = ix86_expand_sse_fabs (xa, NULL); ix86_sse_copysign_to_positive (res, xa, res, mask); @@ -45948,7 +45950,7 @@ ix86_expand_truncdf_32 (rtx operand0, rtx operand1) tmp = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT); /* Remove the sign with FE_DOWNWARD, where x - x = -0.0. */ - if (flag_rounding_math) + if (HONOR_SIGNED_ZEROS (mode) && flag_rounding_math) tmp = ix86_expand_sse_fabs (tmp, NULL); /* res = copysign (xa2, operand1) */ diff --git a/gcc/testsuite/gcc.target/i386/pr96793-2.c b/gcc/testsuite/gcc.target/i386/pr96793-2.c new file mode 100644 index 00000000000..291a2a1d38d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr96793-2.c @@ -0,0 +1,28 @@ +/* PR target/96793 */ +/* { dg-do run { target *-*-linux* *-*-gnu* } } */ +/* { dg-require-effective-target sse2_runtime } */ +/* { dg-options "-O2 -frounding-math -msse2 -mno-sse4 -mfpmath=sse" } */ + +#include <fenv.h> + +double +__attribute__((noinline)) +test (double value) +{ + return __builtin_rint (value); +} + +int +main () +{ + double result; + + fesetround (FE_DOWNWARD); + + result = test (0.25); + + if (__builtin_signbit (result) != 0) + __builtin_abort (); + + return 0; +}
reply other threads:[~2020-12-28 23:18 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201228231813.DBF4B3851C04@sourceware.org \ --to=uros@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).