diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2015-10-27 11:53:45 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2015-10-27 11:53:45 +0000 |
commit | 461e4145898e7bdf5b6a0aec280246c0046fe807 (patch) | |
tree | 6f75e09968688d8fbd36aadce4aec1aef57f54dd | |
parent | 7f54dc834806d508cef6a77a24d9308fd54cf196 (diff) | |
download | gcc-461e4145898e7bdf5b6a0aec280246c0046fe807.zip gcc-461e4145898e7bdf5b6a0aec280246c0046fe807.tar.gz gcc-461e4145898e7bdf5b6a0aec280246c0046fe807.tar.bz2 |
Move copysign folds to match.pd
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
gcc/
* builtins.c (fold_builtin_copysign): Delete.
(fold_builtin_2): Handle constant copysign arguments here.
* match.pd: Add rules previously handled by fold_builtin_copysign.
From-SVN: r229425
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/builtins.c | 51 | ||||
-rw-r--r-- | gcc/match.pd | 10 |
3 files changed, 26 insertions, 41 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dc2638a..7d27d01 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2015-10-27 Richard Sandiford <richard.sandiford@arm.com> + * builtins.c (fold_builtin_copysign): Delete. + (fold_builtin_2): Handle constant copysign arguments here. + * match.pd: Add rules previously handled by fold_builtin_copysign. + +2015-10-27 Richard Sandiford <richard.sandiford@arm.com> + * builtins.c (fold_builtin_signbit): Delete. (fold_builtin_2): Handle constant signbit arguments here. * match.pd: Add rules previously handled by fold_builtin_signbit. diff --git a/gcc/builtins.c b/gcc/builtins.c index ae7e7ef..ed0030d 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7781,46 +7781,6 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree arg2, tree len) return NULL_TREE; } -/* Fold function call to builtin copysign, copysignf or copysignl with - arguments ARG1 and ARG2. Return NULL_TREE if no simplification can - be made. */ - -static tree -fold_builtin_copysign (location_t loc, tree arg1, tree arg2, tree type) -{ - if (!validate_arg (arg1, REAL_TYPE) - || !validate_arg (arg2, REAL_TYPE)) - return NULL_TREE; - - /* copysign(X,X) is X. */ - if (operand_equal_p (arg1, arg2, 0)) - return fold_convert_loc (loc, type, arg1); - - /* If ARG1 and ARG2 are compile-time constants, determine the result. */ - if (TREE_CODE (arg1) == REAL_CST - && TREE_CODE (arg2) == REAL_CST - && !TREE_OVERFLOW (arg1) - && !TREE_OVERFLOW (arg2)) - { - REAL_VALUE_TYPE c1, c2; - - c1 = TREE_REAL_CST (arg1); - c2 = TREE_REAL_CST (arg2); - /* c1.sign := c2.sign. */ - real_copysign (&c1, &c2); - return build_real (type, c1); - } - - /* copysign(X, Y) is fabs(X) when Y is always non-negative. - Remember to evaluate Y for side-effects. */ - if (tree_expr_nonnegative_p (arg2)) - return omit_one_operand_loc (loc, type, - fold_build1_loc (loc, ABS_EXPR, type, arg1), - arg2); - - return NULL_TREE; -} - /* Fold a call to builtin isascii with argument ARG. */ static tree @@ -9278,7 +9238,16 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, tree arg1) break; CASE_FLT_FN (BUILT_IN_COPYSIGN): - return fold_builtin_copysign (loc, arg0, arg1, type); + if (TREE_CODE (arg0) == REAL_CST + && TREE_CODE (arg1) == REAL_CST + && !TREE_OVERFLOW (arg0) + && !TREE_OVERFLOW (arg1)) + { + REAL_VALUE_TYPE c1 = TREE_REAL_CST (arg0); + real_copysign (&c1, TREE_REAL_CST_PTR (arg1)); + return build_real (type, c1); + } + break; CASE_FLT_FN (BUILT_IN_FMIN): return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/false); diff --git a/gcc/match.pd b/gcc/match.pd index b397f0f..ca393e8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2559,6 +2559,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (POW real_onep@0 @1) @0) +(simplify + /* copysign(x,x) -> x. */ + (COPYSIGN @0 @0) + @0) + +(simplify + /* copysign(x,y) -> fabs(x) if y is nonnegative. */ + (COPYSIGN @0 tree_expr_nonnegative_p@1) + (abs @0)) + /* Canonicalization of sequences of math builtins. These rules represent IL simplifications but are not necessarily optimizations. |