Commit b7dce216 by Kyrylo Tkachov Committed by Kyrylo Tkachov

[tree-ssa-math-opts] Expand pow (x, CONST) using square roots when possible

	* params.def (PARAM_MAX_POW_SQRT_DEPTH): New param.
	* tree-ssa-math-opts.c: Include params.h
	(pow_synth_sqrt_info): New struct.
	(representable_as_half_series_p): New function.
	(get_fn_chain): Likewise.
	(print_nested_fn): Likewise.
	(dump_fractional_sqrt_sequence): Likewise.
	(dump_integer_part): Likewise.
	(expand_pow_as_sqrts): Likewise.
	(gimple_expand_builtin_pow): Use above to attempt to expand
	pow as series of square roots.  Removed now unused variables.

	* gcc.target/aarch64/pow-sqrt-synth-1.c: New test.
	* gcc.dg/pow-sqrt.x: New file.
	* gcc.dg/pow-sqrt-1.c: New test.
	* gcc.dg/pow-sqrt-2.c: Likewise.
	* gcc.dg/pow-sqrt-3.c: Likewise.

From-SVN: r223167
parent da80c6b8
2015-05-13 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* params.def (PARAM_MAX_POW_SQRT_DEPTH): New param.
* tree-ssa-math-opts.c: Include params.h
(pow_synth_sqrt_info): New struct.
(representable_as_half_series_p): New function.
(get_fn_chain): Likewise.
(print_nested_fn): Likewise.
(dump_fractional_sqrt_sequence): Likewise.
(dump_integer_part): Likewise.
(expand_pow_as_sqrts): Likewise.
(gimple_expand_builtin_pow): Use above to attempt to expand
pow as series of square roots. Removed now unused variables.
2015-05-13 Uros Bizjak <ubizjak@gmail.com>
* config/alpha/alpha.c (alpha_emit_set_long_const): Remove c1 argument.
......
......@@ -262,6 +262,14 @@ DEFPARAM(PARAM_MAX_HOIST_DEPTH,
"Maximum depth of search in the dominator tree for expressions to hoist",
30, 0, 0)
/* When synthesizing expnonentiation by a real constant operations using square
roots, this controls how deep sqrt chains we are willing to generate. */
DEFPARAM(PARAM_MAX_POW_SQRT_DEPTH,
"max-pow-sqrt-depth",
"Maximum depth of sqrt chains to use when synthesizing exponentiation by a real constant",
5, 1, 32)
/* This parameter limits the number of insns in a loop that will be unrolled,
and by how much the loop is unrolled.
......
2015-05-13 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* gcc.target/aarch64/pow-sqrt-synth-1.c: New test.
* gcc.dg/pow-sqrt.x: New file.
* gcc.dg/pow-sqrt-1.c: New test.
* gcc.dg/pow-sqrt-2.c: Likewise.
* gcc.dg/pow-sqrt-3.c: Likewise.
2015-05-13 Richard Biener <rguenther@suse.de>
PR tree-optimization/66123
......
/* { dg-do run } */
/* { dg-options "-O2 -ffast-math --param max-pow-sqrt-depth=5" } */
#define EXPN (-6 * (0.5*0.5*0.5*0.5))
#include "pow-sqrt.x"
/* { dg-do run } */
/* { dg-options "-O2 -ffast-math --param max-pow-sqrt-depth=5" } */
#define EXPN (-5.875)
#include "pow-sqrt.x"
/* { dg-do run } */
/* { dg-options "-O2 -ffast-math --param max-pow-sqrt-depth=3" } */
#define EXPN (1.25)
#include "pow-sqrt.x"
extern void abort (void);
__attribute__((noinline)) double
real_pow (double x, double pow_exp)
{
return __builtin_pow (x, pow_exp);
}
#define EPS (0.000000000000000000001)
#define SYNTH_POW(X, Y) __builtin_pow (X, Y)
volatile double arg;
int
main (void)
{
double i_arg = 0.1;
for (arg = i_arg; arg < 100.0; arg += 1.0)
{
double synth_res = SYNTH_POW (arg, EXPN);
double real_res = real_pow (arg, EXPN);
if (__builtin_abs (SYNTH_POW (arg, EXPN) - real_pow (arg, EXPN)) > EPS)
abort ();
}
return 0;
}
/* { dg-do compile } */
/* { dg-options "-fdump-tree-sincos -Ofast --param max-pow-sqrt-depth=8" } */
double
foo (double a)
{
return __builtin_pow (a, -5.875);
}
double
foof (double a)
{
return __builtin_pow (a, 0.75f);
}
double
bar (double a)
{
return __builtin_pow (a, 1.0 + 0.00390625);
}
double
baz (double a)
{
return __builtin_pow (a, -1.25) + __builtin_pow (a, 5.75) - __builtin_pow (a, 3.375);
}
#define N 256
void
vecfoo (double *a)
{
for (int i = 0; i < N; i++)
a[i] = __builtin_pow (a[i], 1.25);
}
/* { dg-final { scan-tree-dump-times "synthesizing" 7 "sincos" } } */
/* { dg-final { cleanup-tree-dump "sincos" } } */
\ No newline at end of file
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