From 01ffa370154d0d553874a5fa4e8e54852a8b93e7 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Thu, 25 Jan 2007 04:15:26 +0000 Subject: [PATCH] re PR middle-end/30447 (Evaluate complex math functions at compile-time) PR middle-end/30447 * builtins.c (fold_builtin_cabs): Use MPFR to evaluate a constant argument to cabs and do it without checking for -funsafe-math-optimizations. From-SVN: r121163 --- gcc/ChangeLog | 7 +++++++ gcc/builtins.c | 29 +++++++---------------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 70402852f14..d8f1cddc59c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2007-01-24 Kaveh R. Ghazi + + PR middle-end/30447 + * builtins.c (fold_builtin_cabs): Use MPFR to evaluate a + constant argument to cabs and do it without checking for + -funsafe-math-optimizations. + 2007-01-24 Douglas Gregor * c-common.h (RID_FIRST_CXX0X): New. diff --git a/gcc/builtins.c b/gcc/builtins.c index 19e7d345e53..c33cdf13979 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7021,7 +7021,7 @@ fold_fixed_mathfn (tree fndecl, tree arglist) static tree fold_builtin_cabs (tree arglist, tree type, tree fndecl) { - tree arg; + tree arg, res; if (!arglist || TREE_CHAIN (arglist)) return NULL_TREE; @@ -7031,27 +7031,12 @@ fold_builtin_cabs (tree arglist, tree type, tree fndecl) || TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) != REAL_TYPE) return NULL_TREE; - /* Evaluate cabs of a constant at compile-time. */ - if (flag_unsafe_math_optimizations - && TREE_CODE (arg) == COMPLEX_CST - && TREE_CODE (TREE_REALPART (arg)) == REAL_CST - && TREE_CODE (TREE_IMAGPART (arg)) == REAL_CST - && !TREE_OVERFLOW (TREE_REALPART (arg)) - && !TREE_OVERFLOW (TREE_IMAGPART (arg))) - { - REAL_VALUE_TYPE r, i; - - r = TREE_REAL_CST (TREE_REALPART (arg)); - i = TREE_REAL_CST (TREE_IMAGPART (arg)); - - real_arithmetic (&r, MULT_EXPR, &r, &r); - real_arithmetic (&i, MULT_EXPR, &i, &i); - real_arithmetic (&r, PLUS_EXPR, &r, &i); - if (real_sqrt (&r, TYPE_MODE (type), &r) - || ! flag_trapping_math) - return build_real (type, r); - } - + /* Calculate the result when the argument is a constant. */ + if (TREE_CODE (arg) == COMPLEX_CST + && (res = do_mpfr_arg2 (TREE_REALPART (arg), TREE_IMAGPART (arg), + type, mpfr_hypot))) + return res; + /* If either part is zero, cabs is fabs of the other. */ if (TREE_CODE (arg) == COMPLEX_EXPR && real_zerop (TREE_OPERAND (arg, 0)))