aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-10-28 11:38:32 +0200
committerRichard Biener <rguenther@suse.de>2021-10-28 15:45:22 +0200
commit81342e95827f77c0917dd7a9fd54ac9729439c8e (patch)
tree2e1dd82b395637f69ac307d1e0414a778aaef6d0 /gcc/fold-const.c
parent113dab2b9d511f3aadc30a6a921fc30bd5f93706 (diff)
downloadgcc-81342e95827f77c0917dd7a9fd54ac9729439c8e.zip
gcc-81342e95827f77c0917dd7a9fd54ac9729439c8e.tar.gz
gcc-81342e95827f77c0917dd7a9fd54ac9729439c8e.tar.bz2
middle-end/84407 - honor -frounding-math for int to float conversion
This makes us honor -frounding-math for integer to float conversions and avoid constant folding when such conversion is not exact. 2021-10-28 Richard Biener <rguenther@suse.de> PR middle-end/84407 * fold-const.c (fold_convert_const): Avoid int to float constant folding with -frounding-math and inexact result. * simplify-rtx.c (simplify_const_unary_operation): Likewise for both float and unsigned_float. * gcc.dg/torture/fp-uint64-convert-double-1.c: New testcase. * gcc.dg/torture/fp-uint64-convert-double-2.c: Likewise.
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 18950ae..c7daf871 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2290,7 +2290,20 @@ fold_convert_const (enum tree_code code, tree type, tree arg1)
else if (TREE_CODE (type) == REAL_TYPE)
{
if (TREE_CODE (arg1) == INTEGER_CST)
- return build_real_from_int_cst (type, arg1);
+ {
+ tree res = build_real_from_int_cst (type, arg1);
+ /* Avoid the folding if flag_rounding_math is on and the
+ conversion is not exact. */
+ if (HONOR_SIGN_DEPENDENT_ROUNDING (type))
+ {
+ bool fail = false;
+ wide_int w = real_to_integer (&TREE_REAL_CST (res), &fail,
+ TYPE_PRECISION (TREE_TYPE (arg1)));
+ if (fail || wi::ne_p (w, wi::to_wide (arg1)))
+ return NULL_TREE;
+ }
+ return res;
+ }
else if (TREE_CODE (arg1) == REAL_CST)
return fold_convert_const_real_from_real (type, arg1);
else if (TREE_CODE (arg1) == FIXED_CST)