PR67945: Fix oscillation between pow representations
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 15 Oct 2015 09:50:07 +0000 (09:50 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 15 Oct 2015 09:50:07 +0000 (09:50 +0000)
commit53f3cd25de6706b1850650111a31c0ea0bb63406
treef7cdb50a2dca660b3efaaa1ecd9e1098f74f7df5
parent64da3a9a3f6f01f59be701b3ec55428abb563941
PR67945: Fix oscillation between pow representations

This patch fixes some fallout from my patch to move the sqrt and cbrt
folding rules to match.pd.  The rules included canonicalisations like:

       sqrt(sqrt(x))->pow(x,1/4)

which in the original code was only ever done at the generic level.
My patch meant that we'd do it whenever we tried to fold a gimple
statement, and eventually it would win over the sincos optimisation
that replaces pow(x,1/4) with sqrt(sqrt(x)).

Following a suggestion from Richard B, the patch adds a new
PROP_gimple_* flag to say whether fp routines have been optimised
for the target.  If so, match.pd should only transform calls to math
functions if the result is actually an optimisation, not just an
IL simplification or canonicalisation.  The question then of course
is: which rules are which?  I've added block comments that describe
the criteria I was using.

A slight wart is that we need to use the cfun global to access
the PROP_gimple_* flag; there's no local function pointer available.

Bootstrapped & regression-tested on x86_64-linux-gnu.  Also tested
on powerc64-linux-gnu.

gcc/
PR tree-optimization/67945
* tree-pass.h (PROP_gimple_opt_math): New property flag.
* generic-match-head.c (canonicalize_math_p): New function.
* gimple-match-head.c: Include tree-pass.h.
(canonicalize_math_p): New function.
* match.pd: Group math built-in rules into simplifications
and canonicalizations.  Guard the latter with canonicalize_math_p.
* tree-ssa-math-opts.c (pass_data_cse_sincos): Provide the
PROP_gimple_opt_math property.

From-SVN: r228840
gcc/ChangeLog
gcc/generic-match-head.c
gcc/gimple-match-head.c
gcc/match.pd
gcc/tree-pass.h
gcc/tree-ssa-math-opts.c