aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2007-02-03 16:13:23 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2007-02-03 16:13:23 +0000
commitd1ad84c20452e63a38a6b414a6eb7001711c520a (patch)
tree6f5c23e0e626e6b83e80b93c1170d1bf55370b71 /gcc/builtins.c
parent36f7dcae093c3ed596010a4bf88ce731a7d6236e (diff)
downloadgcc-d1ad84c20452e63a38a6b414a6eb7001711c520a.zip
gcc-d1ad84c20452e63a38a6b414a6eb7001711c520a.tar.gz
gcc-d1ad84c20452e63a38a6b414a6eb7001711c520a.tar.bz2
builtins.c (fold_builtin_cabs): Fold cabs(x+xi) into fabs(x)*sqrt(2).
* builtins.c (fold_builtin_cabs): Fold cabs(x+xi) into fabs(x)*sqrt(2). * fold-const.c (fold_binary): Fix comment typos. Fold complex (x,0)-(0,y) into (x,-y). Likewise (0,y)-(x,0) into (-x,y). testsuite: * gcc.dg/builtins-54.c: Add more cases. From-SVN: r121542
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 5b9a87f..b7ce1e4 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7143,13 +7143,30 @@ fold_builtin_cabs (tree arglist, tree type, tree fndecl)
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)))
- return fold_build1 (ABS_EXPR, type, TREE_OPERAND (arg, 1));
- if (TREE_CODE (arg) == COMPLEX_EXPR
- && real_zerop (TREE_OPERAND (arg, 1)))
- return fold_build1 (ABS_EXPR, type, TREE_OPERAND (arg, 0));
+ if (TREE_CODE (arg) == COMPLEX_EXPR)
+ {
+ tree real = TREE_OPERAND (arg, 0);
+ tree imag = TREE_OPERAND (arg, 1);
+
+ /* If either part is zero, cabs is fabs of the other. */
+ if (real_zerop (real))
+ return fold_build1 (ABS_EXPR, type, imag);
+ if (real_zerop (imag))
+ return fold_build1 (ABS_EXPR, type, real);
+
+ /* cabs(x+xi) -> fabs(x)*sqrt(2). */
+ if (flag_unsafe_math_optimizations
+ && operand_equal_p (real, imag, OEP_PURE_SAME))
+ {
+ REAL_VALUE_TYPE sqrt2;
+
+ real_sqrt (&sqrt2, TYPE_MODE (type), &dconst2);
+ STRIP_NOPS (real);
+ return fold_build2 (MULT_EXPR, type,
+ fold_build1 (ABS_EXPR, type, real),
+ build_real (type, sqrt2));
+ }
+ }
/* Optimize cabs(-z) and cabs(conj(z)) as cabs(z). */
if (TREE_CODE (arg) == NEGATE_EXPR