aboutsummaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2008-10-29 17:05:42 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2008-10-29 17:05:42 +0000
commit20ded7a68b10f9c2d1aaa94e89df494bf0ce41a0 (patch)
treef0bc48b745fe374d4990579d0ef02a2d88bb7799 /gcc/real.c
parent669eeb28eaad6f3cb79d48a5e4176775befe0429 (diff)
downloadgcc-20ded7a68b10f9c2d1aaa94e89df494bf0ce41a0.zip
gcc-20ded7a68b10f9c2d1aaa94e89df494bf0ce41a0.tar.gz
gcc-20ded7a68b10f9c2d1aaa94e89df494bf0ce41a0.tar.bz2
re PR middle-end/36578 (cast to long double not taken into account when result stored to a double)
PR middle-end/36578 * convert.c (convert_to_real): Do not optimize conversions of binary arithmetic operations between binary and decimal floating-point types. Consider mode of target type in determining decimal type for arithmetic. Unless flag_unsafe_math_optimizations, do not optimize binary conversions where this may change rounding behavior. * real.c (real_can_shorten_arithmetic): New. * real.h (real_can_shorten_arithmetic): Declare. testsuite: * gcc.dg/dfp/convert-bfp-13.c, gcc.dg/dfp/convert-bfp-14.c, gcc.dg/dfp/convert-dfp-fold-2.c, gcc.target/i386/pr36578-1.c, gcc.target/i386/pr36578-2.c: New tests. From-SVN: r141432
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/real.c b/gcc/real.c
index dc6d748..c5a16a8 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -1266,6 +1266,35 @@ exact_real_inverse (enum machine_mode mode, REAL_VALUE_TYPE *r)
*r = u;
return true;
}
+
+/* Return true if arithmetic on values in IMODE that were promoted
+ from values in TMODE is equivalent to direct arithmetic on values
+ in TMODE. */
+
+bool
+real_can_shorten_arithmetic (enum machine_mode imode, enum machine_mode tmode)
+{
+ const struct real_format *tfmt, *ifmt;
+ tfmt = REAL_MODE_FORMAT (tmode);
+ ifmt = REAL_MODE_FORMAT (imode);
+ /* These conditions are conservative rather than trying to catch the
+ exact boundary conditions; the main case to allow is IEEE float
+ and double. */
+ return (ifmt->b == tfmt->b
+ && ifmt->p > 2 * tfmt->p
+ && ifmt->emin < 2 * tfmt->emin - tfmt->p - 2
+ && ifmt->emin < tfmt->emin - tfmt->emax - tfmt->p - 2
+ && ifmt->emax > 2 * tfmt->emax + 2
+ && ifmt->emax > tfmt->emax - tfmt->emin + tfmt->p + 2
+ && ifmt->round_towards_zero == tfmt->round_towards_zero
+ && (ifmt->has_sign_dependent_rounding
+ == tfmt->has_sign_dependent_rounding)
+ && ifmt->has_nans >= tfmt->has_nans
+ && ifmt->has_inf >= tfmt->has_inf
+ && ifmt->has_signed_zero >= tfmt->has_signed_zero
+ && !MODE_COMPOSITE_P (tmode)
+ && !MODE_COMPOSITE_P (imode));
+}
/* Render R as an integer. */