This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Simplify pow with constant
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: nd <nd at arm dot com>
- Date: Fri, 4 Aug 2017 11:23:06 +0000
- Subject: [PATCH] Simplify pow with constant
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
This patch simplifies pow (C, x) into exp (x * C1), where C1 = log (C).
Do this only for fast-math as accuracy is reduced. This is much faster
since pow is more complex than exp - with a current GLIBC the speedup
is more than 7 times for this transformation.
ChangeLog:
2017-08-04 Wilco Dijkstra <wdijkstr@arm.com>
* match.pd: Add pow (C, x) simplification.
--
diff --git a/gcc/match.pd b/gcc/match.pd
index e98db52af84946cf579c6434e06d450713a47162..96486aa1f512fe32d85a1de95c46523263ea1b6d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3548,6 +3548,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(logs (pows @0 @1))
(mult @1 (logs @0))))
+ /* pow(C,x) -> exp(log(C)*x). */
+ (for pows (POW)
+ exps (EXP)
+ logs (LOG)
+ (simplify
+ (pows REAL_CST@0 @1)
+ (exps (mult (logs @0) @1))))
+
(for sqrts (SQRT)
cbrts (CBRT)
pows (POW)