summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-22 08:32:01 +0000
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-22 08:32:01 +0000
commit390c3cff5e0bb12d5d33692025eaab3c821a6931 (patch)
tree80022a09c55f138c2131bfb05b749ba87d72d72c
parent92f3c1b294f122abfc91d935d58f3fc5809d046c (diff)
downloadgcc-390c3cff5e0bb12d5d33692025eaab3c821a6931.tar.gz
Move tan simplifications to match.pd
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * builtins.c (fold_builtin_tan): Delete. (fold_builtin_1): Handle constant tan arguments here. * match.pd: Simplify (tan (atan x)) to x. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229166 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/builtins.c32
-rw-r--r--gcc/match.pd10
3 files changed, 18 insertions, 30 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bd5aef52c91..2ec877a9256 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2015-10-22 Richard Sandiford <richard.sandiford@arm.com>
+ * builtins.c (fold_builtin_tan): Delete.
+ (fold_builtin_1): Handle constant tan arguments here.
+ * match.pd: Simplify (tan (atan x)) to x.
+
+2015-10-22 Richard Sandiford <richard.sandiford@arm.com>
+
* builtins.c (fold_builtin_cproj): Delete.
(fold_builtin_1): Handle constant arguments here.
(build_complex_cproj): Move and rename to...
diff --git a/gcc/builtins.c b/gcc/builtins.c
index eec4b8898c1..02bf9f65a33 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -160,7 +160,6 @@ static rtx expand_builtin_fabs (tree, rtx, rtx);
static rtx expand_builtin_signbit (tree, rtx);
static tree fold_builtin_pow (location_t, tree, tree, tree, tree);
static tree fold_builtin_powi (location_t, tree, tree, tree, tree);
-static tree fold_builtin_tan (tree, tree);
static tree fold_builtin_trunc (location_t, tree, tree);
static tree fold_builtin_floor (location_t, tree, tree);
static tree fold_builtin_ceil (location_t, tree, tree);
@@ -7538,33 +7537,6 @@ fold_fixed_mathfn (location_t loc, tree fndecl, tree 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. */
-
-static tree
-fold_builtin_tan (tree arg, tree type)
-{
- enum built_in_function fcode;
- tree res;
-
- if (!validate_arg (arg, REAL_TYPE))
- return NULL_TREE;
-
- /* Calculate the result when the argument is a constant. */
- if ((res = do_mpfr_arg1 (arg, type, mpfr_tan, NULL, NULL, 0)))
- return res;
-
- /* Optimize tan(atan(x)) = x. */
- fcode = builtin_mathfn_code (arg);
- if (flag_unsafe_math_optimizations
- && (fcode == BUILT_IN_ATAN
- || fcode == BUILT_IN_ATANF
- || fcode == BUILT_IN_ATANL))
- return CALL_EXPR_ARG (arg, 0);
-
- return NULL_TREE;
-}
-
/* Fold function call to builtin sincos, sincosf, or sincosl. Return
NULL_TREE if no simplification can be made. */
@@ -9612,7 +9584,9 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
break;
CASE_FLT_FN (BUILT_IN_TAN):
- return fold_builtin_tan (arg0, type);
+ if (validate_arg (arg0, REAL_TYPE))
+ return do_mpfr_arg1 (arg0, type, mpfr_tan, NULL, NULL, 0);
+ break;
CASE_FLT_FN (BUILT_IN_CEXP):
return fold_builtin_cexp (loc, arg0, type);
diff --git a/gcc/match.pd b/gcc/match.pd
index 6b181897e2b..1ba43c44c16 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. If not see
(define_operator_list SIN BUILT_IN_SINF BUILT_IN_SIN BUILT_IN_SINL)
(define_operator_list COS BUILT_IN_COSF BUILT_IN_COS BUILT_IN_COSL)
(define_operator_list TAN BUILT_IN_TANF BUILT_IN_TAN BUILT_IN_TANL)
+(define_operator_list ATAN BUILT_IN_ATANF BUILT_IN_ATAN BUILT_IN_ATANL)
(define_operator_list COSH BUILT_IN_COSHF BUILT_IN_COSH BUILT_IN_COSHL)
(define_operator_list CEXPI BUILT_IN_CEXPIF BUILT_IN_CEXPI BUILT_IN_CEXPIL)
(define_operator_list CPROJ BUILT_IN_CPROJF BUILT_IN_CPROJ BUILT_IN_CPROJL)
@@ -2374,7 +2375,14 @@ along with GCC; see the file COPYING3. If not see
/* cbrt(expN(x)) -> expN(x/3). */
(simplify
(cbrts (exps @0))
- (exps (mult @0 { build_real_truncate (type, dconst_third ()); })))))
+ (exps (mult @0 { build_real_truncate (type, dconst_third ()); }))))
+
+ /* tan(atan(x)) -> x. */
+ (for tans (TAN)
+ atans (ATAN)
+ (simplify
+ (tans (atans @0))
+ @0)))
/* cabs(x+0i) or cabs(0+xi) -> abs(x). */
(simplify