aboutsummaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2015-10-13 07:34:41 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2015-10-13 07:34:41 +0000
commit9b054b08813d37586d6765fd087b0fc85dc94daf (patch)
treece58f25ea3acb2f496d0e9a22bb891f6e38e668d /gcc/match.pd
parent6696de8a7f7e9bf37e2b9358ad5608dc863ad7a4 (diff)
downloadgcc-9b054b08813d37586d6765fd087b0fc85dc94daf.zip
gcc-9b054b08813d37586d6765fd087b0fc85dc94daf.tar.gz
gcc-9b054b08813d37586d6765fd087b0fc85dc94daf.tar.bz2
To...
To: gcc-patches@gcc.gnu.org Subject: Add an extra pow rule to match.pd From: Richard Sandiford <richard.sandiford@arm.com> Gcc: private.sent --text follows this line-- Simplify pow(|x|,y) and pow(-x,y) to pow(x,y) if y is an even integer. At the moment this duplicates a case in fold_builtin_pow, but an upcoming patch will move all the fold_builtin_pow rules to match.pd. I'm doing this one early to fix a regression in builtin-10.c for soft-float ARM. gcc/ * real.h (real_isinteger): Declare. * real.c (real_isinteger): New function. * match.pd: Simplify pow(|x|,y) and pow(-x,y) to pow(x,y) if y is an even integer. From-SVN: r228750
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd17
1 files changed, 12 insertions, 5 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index b02dd03..6714796 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -309,12 +309,19 @@ along with GCC; see the file COPYING3. If not see
&& TYPE_OVERFLOW_UNDEFINED (type))
@0)))
-/* Simplify cos (-x) -> cos (x). */
(for op (negate abs)
-(for coss (COS COSH)
- (simplify
- (coss (op @0))
- (coss @0))))
+ /* Simplify cos(-x) and cos(|x|) -> cos(x). Similarly for cosh. */
+ (for coss (COS COSH)
+ (simplify
+ (coss (op @0))
+ (coss @0)))
+ /* Simplify pow(-x, y) and pow(|x|,y) -> pow(x,y) if y is an even integer. */
+ (for pows (POW)
+ (simplify
+ (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))))))
/* X % Y is smaller than Y. */
(for cmp (lt ge)