From: rsandifo Date: Wed, 21 Oct 2015 09:49:13 +0000 (+0000) Subject: Add simple sign-stripping cases to match.pd X-Git-Tag: upstream/6.1~3911 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a15183ebb8e553d7cb4e33c7f5dd546303126010;p=platform%2Fupstream%2Flinaro-gcc.git Add simple sign-stripping cases to match.pd This patch makes sure that, for every simplification that uses fold_strip_sign_ops, there are associated match.pd rules for the leaf sign ops, i.e. abs, negate and copysign. A follow-on patch will add a pass to handle more complex cases. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. gcc/ * match.pd: Add rules to simplify ccos, ccosh, hypot, copysign and x*x in cases where the operands are sign ops. Extend these rules to handle copysign as a sign op (including for cos, cosh and pow, which already treated negate and abs as sign ops). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229123 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 949fb3a..28cafa1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-10-21 Richard Sandiford + + * match.pd: Add rules to simplify ccos, ccosh, hypot, copysign + and x*x in cases where the operands are sign ops. Extend these + rules to handle copysign as a sign op (including for cos, cosh + and pow, which already treated negate and abs as sign ops). + 2015-10-21 Uros Bizjak PR target/68018 diff --git a/gcc/match.pd b/gcc/match.pd index 83dc7ad..c5aa001 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -62,6 +62,12 @@ along with GCC; see the file COPYING3. If not see (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) +(define_operator_list CCOS BUILT_IN_CCOSF BUILT_IN_CCOS BUILT_IN_CCOSL) +(define_operator_list CCOSH BUILT_IN_CCOSHF BUILT_IN_CCOSH BUILT_IN_CCOSHL) +(define_operator_list HYPOT BUILT_IN_HYPOTF BUILT_IN_HYPOT BUILT_IN_HYPOTL) +(define_operator_list COPYSIGN BUILT_IN_COPYSIGNF + BUILT_IN_COPYSIGN + BUILT_IN_COPYSIGNL) /* Simplifications of operations with one constant operand and simplifications to constants or single values. */ @@ -323,7 +329,70 @@ along with GCC; see the file COPYING3. If not see (pows (op @0) REAL_CST@1) (with { HOST_WIDE_INT n; } (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0) - (pows @0 @1)))))) + (pows @0 @1))))) + /* Strip negate and abs from both operands of hypot. */ + (for hypots (HYPOT) + (simplify + (hypots (op @0) @1) + (hypots @0 @1)) + (simplify + (hypots @0 (op @1)) + (hypots @0 @1))) + /* copysign(-x, y) and copysign(abs(x), y) -> copysign(x, y). */ + (for copysigns (COPYSIGN) + (simplify + (copysigns (op @0) @1) + (copysigns @0 @1)))) + +/* abs(x)*abs(x) -> x*x. Should be valid for all types. */ +(simplify + (mult (abs@1 @0) @1) + (mult @0 @0)) + +/* cos(copysign(x, y)) -> cos(x). Similarly for cosh. */ +(for coss (COS COSH) + copysigns (COPYSIGN) + (simplify + (coss (copysigns @0 @1)) + (coss @0))) + +/* pow(copysign(x, y), z) -> pow(x, z) if z is an even integer. */ +(for pows (POW) + copysigns (COPYSIGN) + (simplify + (pows (copysigns @0 @1) REAL_CST@1) + (with { HOST_WIDE_INT n; } + (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0) + (pows @0 @1))))) + +(for hypots (HYPOT) + copysigns (COPYSIGN) + /* hypot(copysign(x, y), z) -> hypot(x, z). */ + (simplify + (hypots (copysigns @0 @1) @2) + (hypots @0 @2)) + /* hypot(x, copysign(y, z)) -> hypot(x, y). */ + (simplify + (hypots @0 (copysigns @1 @2)) + (hypots @0 @1))) + +/* copysign(copysign(x, y), z) -> copysign(x, z). */ +(for copysigns (COPYSIGN) + (simplify + (copysigns (copysigns @0 @1) @2) + (copysigns @0 @2))) + +/* copysign(x,y)*copysign(x,y) -> x*x. */ +(for copysigns (COPYSIGN) + (simplify + (mult (copysigns@2 @0 @1) @2) + (mult @0 @0))) + +/* ccos(-x) -> ccos(x). Similarly for ccosh. */ +(for ccoss (CCOS CCOSH) + (simplify + (ccoss (negate @0)) + (ccoss @0))) /* Fold (a * (1 << b)) into (a << b) */ (simplify