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 <rguent...@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