diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2015-10-22 08:27:04 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2015-10-22 08:27:04 +0000 |
commit | 92c52eab974ce9e1c81d770724adb56846bcaa4b (patch) | |
tree | 84842493f9d814e607d6df00c0278469f3159f10 /gcc/builtins.c | |
parent | 7477de01a8c9c4f496d6f4daea90255ec0aad272 (diff) | |
download | gcc-92c52eab974ce9e1c81d770724adb56846bcaa4b.zip gcc-92c52eab974ce9e1c81d770724adb56846bcaa4b.tar.gz gcc-92c52eab974ce9e1c81d770724adb56846bcaa4b.tar.bz2 |
Move more cproj simplifications to match.pd
Also make build_complex_cproj available globally and use
it for the existing match.pd rules.
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
gcc/
* builtins.c (fold_builtin_cproj): Delete.
(fold_builtin_1): Handle constant arguments here.
(build_complex_cproj): Move and rename to...
* tree.c: (build_complex_inf): ...this.
* tree.h (build_complex_inf): Declare.
* match.pd: Fold cproj(x)->x if x has no infinity.
Use build_complex_inf for existing cproj rules.
From-SVN: r229164
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 59 |
1 files changed, 14 insertions, 45 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 2318b28..eec4b88 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7538,50 +7538,6 @@ fold_fixed_mathfn (location_t loc, tree fndecl, tree arg) return NULL_TREE; } -/* Build a complex (inf +- 0i) for the result of cproj. TYPE is the - complex tree type of the result. If NEG is true, the imaginary - zero is negative. */ - -static tree -build_complex_cproj (tree type, bool neg) -{ - REAL_VALUE_TYPE rinf, rzero = dconst0; - - real_inf (&rinf); - rzero.sign = neg; - return build_complex (type, build_real (TREE_TYPE (type), rinf), - build_real (TREE_TYPE (type), rzero)); -} - -/* Fold call to builtin cproj, cprojf or cprojl with argument ARG. TYPE is the - return type. Return NULL_TREE if no simplification can be made. */ - -static tree -fold_builtin_cproj (location_t loc, tree arg, tree type) -{ - if (!validate_arg (arg, COMPLEX_TYPE) - || TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) != REAL_TYPE) - return NULL_TREE; - - /* If there are no infinities, return arg. */ - if (! HONOR_INFINITIES (type)) - return non_lvalue_loc (loc, arg); - - /* Calculate the result when the argument is a constant. */ - if (TREE_CODE (arg) == COMPLEX_CST) - { - const REAL_VALUE_TYPE *real = TREE_REAL_CST_PTR (TREE_REALPART (arg)); - const REAL_VALUE_TYPE *imag = TREE_REAL_CST_PTR (TREE_IMAGPART (arg)); - - if (real_isinf (real) || real_isinf (imag)) - return build_complex_cproj (type, imag->sign); - else - return arg; - } - - return NULL_TREE; -} - /* Fold function call to builtin tan, tanf, or tanl with argument ARG. Return NULL_TREE if no simplification can be made. */ @@ -9504,7 +9460,20 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0) break; CASE_FLT_FN (BUILT_IN_CPROJ): - return fold_builtin_cproj (loc, arg0, type); + if (TREE_CODE (arg0) == COMPLEX_CST + && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE) + { + const REAL_VALUE_TYPE *real + = TREE_REAL_CST_PTR (TREE_REALPART (arg0)); + const REAL_VALUE_TYPE *imag + = TREE_REAL_CST_PTR (TREE_IMAGPART (arg0)); + + if (real_isinf (real) || real_isinf (imag)) + return build_complex_inf (type, imag->sign); + else + return arg0; + } + break; CASE_FLT_FN (BUILT_IN_CSIN): if (validate_arg (arg0, COMPLEX_TYPE) |