public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] middle-end/57245 - honor -frounding-math in real truncation
@ 2021-10-27 13:20 Richard Biener
  2021-10-27 13:41 ` Jakub Jelinek
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2021-10-27 13:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: joseph

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-17 14:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 13:20 [PATCH] middle-end/57245 - honor -frounding-math in real truncation Richard Biener
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

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