Commit 01ffa370 by Kaveh R. Ghazi Committed by Kaveh Ghazi

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
parent e1f1ee86
2007-01-24 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
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 <dgregor@osl.iu.edu> 2007-01-24 Douglas Gregor <dgregor@osl.iu.edu>
* c-common.h (RID_FIRST_CXX0X): New. * c-common.h (RID_FIRST_CXX0X): New.
......
...@@ -7021,7 +7021,7 @@ fold_fixed_mathfn (tree fndecl, tree arglist) ...@@ -7021,7 +7021,7 @@ fold_fixed_mathfn (tree fndecl, tree arglist)
static tree static tree
fold_builtin_cabs (tree arglist, tree type, tree fndecl) fold_builtin_cabs (tree arglist, tree type, tree fndecl)
{ {
tree arg; tree arg, res;
if (!arglist || TREE_CHAIN (arglist)) if (!arglist || TREE_CHAIN (arglist))
return NULL_TREE; return NULL_TREE;
...@@ -7031,27 +7031,12 @@ fold_builtin_cabs (tree arglist, tree type, tree fndecl) ...@@ -7031,27 +7031,12 @@ fold_builtin_cabs (tree arglist, tree type, tree fndecl)
|| TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) != REAL_TYPE) || TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) != REAL_TYPE)
return NULL_TREE; return NULL_TREE;
/* Evaluate cabs of a constant at compile-time. */ /* Calculate the result when the argument is a constant. */
if (flag_unsafe_math_optimizations if (TREE_CODE (arg) == COMPLEX_CST
&& TREE_CODE (arg) == COMPLEX_CST && (res = do_mpfr_arg2 (TREE_REALPART (arg), TREE_IMAGPART (arg),
&& TREE_CODE (TREE_REALPART (arg)) == REAL_CST type, mpfr_hypot)))
&& TREE_CODE (TREE_IMAGPART (arg)) == REAL_CST return res;
&& !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);
}
/* If either part is zero, cabs is fabs of the other. */ /* If either part is zero, cabs is fabs of the other. */
if (TREE_CODE (arg) == COMPLEX_EXPR if (TREE_CODE (arg) == COMPLEX_EXPR
&& real_zerop (TREE_OPERAND (arg, 0))) && real_zerop (TREE_OPERAND (arg, 0)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment