Commit 53f3cd25 by Richard Sandiford Committed by Richard Sandiford

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
parent 64da3a9a
2015-10-15 Richard Sandiford <richard.sandiford@arm.com>
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.
2015-10-15 Marek Polacek <polacek@redhat.com> 2015-10-15 Marek Polacek <polacek@redhat.com>
PR tree-optimization/67953 PR tree-optimization/67953
...@@ -73,3 +73,12 @@ single_use (tree t ATTRIBUTE_UNUSED) ...@@ -73,3 +73,12 @@ single_use (tree t ATTRIBUTE_UNUSED)
{ {
return true; return true;
} }
/* Return true if math operations should be canonicalized,
e.g. sqrt(sqrt(x)) -> pow(x, 0.25). */
static inline bool
canonicalize_math_p ()
{
return true;
}
...@@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see
#include "target.h" #include "target.h"
#include "cgraph.h" #include "cgraph.h"
#include "gimple-match.h" #include "gimple-match.h"
#include "tree-pass.h"
/* Forward declarations of the private auto-generated matchers. /* Forward declarations of the private auto-generated matchers.
...@@ -825,3 +826,12 @@ single_use (tree t) ...@@ -825,3 +826,12 @@ single_use (tree t)
{ {
return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t); return TREE_CODE (t) != SSA_NAME || has_zero_uses (t) || has_single_use (t);
} }
/* Return true if math operations should be canonicalized,
e.g. sqrt(sqrt(x)) -> pow(x, 0.25). */
static inline bool
canonicalize_math_p ()
{
return !cfun || (cfun->curr_properties & PROP_gimple_opt_math) == 0;
}
...@@ -222,6 +222,10 @@ protected: ...@@ -222,6 +222,10 @@ protected:
#define PROP_gimple_lvec (1 << 12) /* lowered vector */ #define PROP_gimple_lvec (1 << 12) /* lowered vector */
#define PROP_gimple_eomp (1 << 13) /* no OpenMP directives */ #define PROP_gimple_eomp (1 << 13) /* no OpenMP directives */
#define PROP_gimple_lva (1 << 14) /* No va_arg internal function. */ #define PROP_gimple_lva (1 << 14) /* No va_arg internal function. */
#define PROP_gimple_opt_math (1 << 15) /* Disable canonicalization
of math functions; the
current choices have
been optimized. */
#define PROP_trees \ #define PROP_trees \
(PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp) (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)
......
...@@ -1689,7 +1689,7 @@ const pass_data pass_data_cse_sincos = ...@@ -1689,7 +1689,7 @@ const pass_data pass_data_cse_sincos =
OPTGROUP_NONE, /* optinfo_flags */ OPTGROUP_NONE, /* optinfo_flags */
TV_NONE, /* tv_id */ TV_NONE, /* tv_id */
PROP_ssa, /* properties_required */ PROP_ssa, /* properties_required */
0, /* properties_provided */ PROP_gimple_opt_math, /* properties_provided */
0, /* properties_destroyed */ 0, /* properties_destroyed */
0, /* todo_flags_start */ 0, /* todo_flags_start */
TODO_update_ssa, /* todo_flags_finish */ TODO_update_ssa, /* todo_flags_finish */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment