public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: joseph@codesourcery.com
Subject: [PATCH] middle-end/57245 - honor -frounding-math in real truncation
Date: Wed, 27 Oct 2021 15:20:29 +0200 (CEST)	[thread overview]
Message-ID: <99s854-94r4-8823-6n80-nq081641son@fhfr.qr> (raw)

The following honors -frounding-math when converting a FP constant
to another FP type.

Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?

I wonder what a good way to test this in a portable way, the bugreport
unfortunately didn't contain something executable and I don't see
much -frounding-math test coverage to copy from.

Thanks,
Richard.

2021-10-27  Richard Biener  <rguenther@suse.de>

	PR middle-end/57245
	* fold-const.c (fold_convert_const_real_from_real): Honor
	-frounding-math if the conversion is not exact.
---
 gcc/fold-const.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index ff23f12f33c..c7aebf9cc7e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2139,6 +2139,12 @@ fold_convert_const_real_from_real (tree type, const_tree arg1)
       && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg1)))
     return NULL_TREE; 
 
+  /* With flag_rounding_math we shuld respect the current rounding mode
+     unless the conversion is exact.  */
+  if (HONOR_SIGN_DEPENDENT_ROUNDING (arg1)
+      && !exact_real_truncate (TYPE_MODE (type), &TREE_REAL_CST (arg1)))
+    return NULL_TREE;
+
   real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1));
   t = build_real (type, value);
 
-- 
2.31.1

             reply	other threads:[~2021-10-27 13:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 13:20 Richard Biener [this message]
2021-10-27 13:41 ` Jakub Jelinek
2021-10-27 14:29   ` Richard Biener
2021-10-27 14:44     ` Jakub Jelinek
2021-10-27 15:52       ` Richard Biener
2021-10-28  8:11         ` Richard Biener
2021-10-28  9:22           ` Jakub Jelinek
2021-12-17 14:25             ` H.J. Lu

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=99s854-94r4-8823-6n80-nq081641son@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /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: link
Be 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).