Commit 0bfbca58 by Jakub Jelinek

re PR tree-optimization/56125 (-O2 -ffast-math generates bad code when dividing…

re PR tree-optimization/56125 (-O2 -ffast-math generates bad code when dividing a double by the square of another double.)

	PR tree-optimization/56125
	* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Don't optimize
	pow(x,c) into sqrt(x) * powi(x, n/2) or
	1.0 / (sqrt(x) * powi(x, abs(n/2))) if c is an integer or when
	optimizing for size.
	Don't optimize pow(x,c) into powi(x, n/3) * powi(cbrt(x), n%3) or
	1.0 / (powi(x, abs(n)/3) * powi(cbrt(x), abs(n)%3)) if 2c is an
	integer.

	* gcc.dg/pr56125.c: New test.

From-SVN: r195507
parent dd8b9dde
2013-01-28 Jakub Jelinek <jakub@redhat.com> 2013-01-28 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/56125
* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Don't optimize
pow(x,c) into sqrt(x) * powi(x, n/2) or
1.0 / (sqrt(x) * powi(x, abs(n/2))) if c is an integer or when
optimizing for size.
Don't optimize pow(x,c) into powi(x, n/3) * powi(cbrt(x), n%3) or
1.0 / (powi(x, abs(n)/3) * powi(cbrt(x), abs(n)%3)) if 2c is an
integer.
PR tree-optimization/56094 PR tree-optimization/56094
* gimplify.c (force_gimple_operand_1): Temporarily set input_location * gimplify.c (force_gimple_operand_1): Temporarily set input_location
to UNKNOWN_LOCATION while gimplifying expr. to UNKNOWN_LOCATION while gimplifying expr.
...@@ -11,19 +20,18 @@ ...@@ -11,19 +20,18 @@
operand 0 in movabs insn template for -masm=intel asm alternative. operand 0 in movabs insn template for -masm=intel asm alternative.
(*movabs<mode>_2): Ditto for operand 1. (*movabs<mode>_2): Ditto for operand 1.
2013-01-26 David Holsgrove <david.holsgrove@xilinx.com> 2013-01-26 David Holsgrove <david.holsgrove@xilinx.com>
PR target/54663 PR target/54663
* config.gcc (microblaze*-linux*): Add tmake_file to allow building * config.gcc (microblaze*-linux*): Add tmake_file to allow building
of microblaze-c.o of microblaze-c.o
2013-01-26 Edgar E. Iglesias <edgar.iglesias@gmail.com> 2013-01-26 Edgar E. Iglesias <edgar.iglesias@gmail.com>
* config.gcc (microblaze*-*-*): Rename microblaze*-*-elf, update * config.gcc (microblaze*-*-*): Rename microblaze*-*-elf, update
tm_file. tm_file.
2013-01-25 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
2013-01-25 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
* config/aarch64/aarch64.c (TARGET_FIXED_CONDITION_CODE_REGS): * config/aarch64/aarch64.c (TARGET_FIXED_CONDITION_CODE_REGS):
Undef to avoid warning. Undef to avoid warning.
...@@ -369,7 +377,7 @@ ...@@ -369,7 +377,7 @@
* config/aarch64/arm_neon.h: Map scalar types to standard types. * config/aarch64/arm_neon.h: Map scalar types to standard types.
2013-01-18 Alexandre Oliva <aoliva@redhat.com> 2013-01-18 Alexandre Oliva <aoliva@redhat.com>
PR debug/54114 PR debug/54114
PR debug/54402 PR debug/54402
...@@ -392,13 +400,13 @@ ...@@ -392,13 +400,13 @@
cache, respectively. cache, respectively.
* alias.c (rtx_equal_for_memref_p): Compare operands of ENTRY_VALUEs. * alias.c (rtx_equal_for_memref_p): Compare operands of ENTRY_VALUEs.
2013-01-18 Alexandre Oliva <aoliva@redhat.com> 2013-01-18 Alexandre Oliva <aoliva@redhat.com>
PR libmudflap/53359 PR libmudflap/53359
* tree-mudflap.c (mudflap_finish_file): Skip deferred decls * tree-mudflap.c (mudflap_finish_file): Skip deferred decls
not found in the symtab. not found in the symtab.
2013-01-18 Alexandre Oliva <aoliva@redhat.com> 2013-01-18 Alexandre Oliva <aoliva@redhat.com>
PR debug/56006 PR debug/56006
PR rtl-optimization/55547 PR rtl-optimization/55547
...@@ -542,7 +550,7 @@ ...@@ -542,7 +550,7 @@
(expand_atomic_load): Ditto. (expand_atomic_load): Ditto.
(expand_atomic_store): Ditto. (expand_atomic_store): Ditto.
2013-01-16 Alexandre Oliva <aoliva@redhat.com> 2013-01-16 Alexandre Oliva <aoliva@redhat.com>
PR rtl-optimization/55547 PR rtl-optimization/55547
PR rtl-optimization/53827 PR rtl-optimization/53827
...@@ -1101,7 +1109,7 @@ ...@@ -1101,7 +1109,7 @@
(asan_finish_file): Test it here instead. (asan_finish_file): Test it here instead.
2013-01-07 Nick Clifton <nickc@redhat.com> 2013-01-07 Nick Clifton <nickc@redhat.com>
Matthias Klose <doko@debian.org> Matthias Klose <doko@debian.org>
Doug Kwan <dougkwan@google.com> Doug Kwan <dougkwan@google.com>
H.J. Lu <hongjiu.lu@intel.com> H.J. Lu <hongjiu.lu@intel.com>
......
2013-01-28 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/56125
* gcc.dg/pr56125.c: New test.
2013-01-28 Tobias Burnus <burnus@net-b.de> 2013-01-28 Tobias Burnus <burnus@net-b.de>
Mikael Morin <mikael@gcc.gnu.org> Mikael Morin <mikael@gcc.gnu.org>
...@@ -157,7 +162,7 @@ ...@@ -157,7 +162,7 @@
* lib/target-supports.exp (check_effective_target_alias): New. * lib/target-supports.exp (check_effective_target_alias): New.
2013-01-20 Jack Howarth <howarth@bromo.med.uc.edu> 2013-01-20 Jack Howarth <howarth@bromo.med.uc.edu>
PR debug/53235 PR debug/53235
* g++.dg/debug/dwarf2/nested-4.C: XFAIL on darwin. * g++.dg/debug/dwarf2/nested-4.C: XFAIL on darwin.
...@@ -217,7 +222,7 @@ ...@@ -217,7 +222,7 @@
PR rtl-optimization/52573 PR rtl-optimization/52573
* gcc.dg/pr52573.c: New test. * gcc.dg/pr52573.c: New test.
2013-01-17 Jack Howarth <howarth@bromo.med.uc.edu> 2013-01-17 Jack Howarth <howarth@bromo.med.uc.edu>
PR sanitizer/55679 PR sanitizer/55679
* g++.dg/asan/interception-test-1.C: Skip on darwin. * g++.dg/asan/interception-test-1.C: Skip on darwin.
......
/* PR tree-optimization/56125 */
/* { dg-do run } */
/* { dg-options "-O2 -ffast-math" } */
extern void abort (void);
extern double fabs (double);
__attribute__((cold)) double
foo (double x, double n)
{
double u = x / (n * n);
return u;
}
int
main ()
{
if (fabs (foo (29, 2) - 7.25) > 0.001)
abort ();
return 0;
}
...@@ -1110,7 +1110,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc, ...@@ -1110,7 +1110,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
HOST_WIDE_INT n; HOST_WIDE_INT n;
tree type, sqrtfn, cbrtfn, sqrt_arg0, sqrt_sqrt, result, cbrt_x, powi_cbrt_x; tree type, sqrtfn, cbrtfn, sqrt_arg0, sqrt_sqrt, result, cbrt_x, powi_cbrt_x;
enum machine_mode mode; enum machine_mode mode;
bool hw_sqrt_exists; bool hw_sqrt_exists, c_is_int, c2_is_int;
/* If the exponent isn't a constant, there's nothing of interest /* If the exponent isn't a constant, there's nothing of interest
to be done. */ to be done. */
...@@ -1122,8 +1122,9 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc, ...@@ -1122,8 +1122,9 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
c = TREE_REAL_CST (arg1); c = TREE_REAL_CST (arg1);
n = real_to_integer (&c); n = real_to_integer (&c);
real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0); real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);
c_is_int = real_identical (&c, &cint);
if (real_identical (&c, &cint) if (c_is_int
&& ((n >= -1 && n <= 2) && ((n >= -1 && n <= 2)
|| (flag_unsafe_math_optimizations || (flag_unsafe_math_optimizations
&& optimize_insn_for_speed_p () && optimize_insn_for_speed_p ()
...@@ -1221,7 +1222,8 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc, ...@@ -1221,7 +1222,8 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
return build_and_insert_call (gsi, loc, cbrtfn, sqrt_arg0); return build_and_insert_call (gsi, loc, cbrtfn, sqrt_arg0);
} }
/* Optimize pow(x,c), where n = 2c for some nonzero integer n, into /* Optimize pow(x,c), where n = 2c for some nonzero integer n
and c not an integer, into
sqrt(x) * powi(x, n/2), n > 0; sqrt(x) * powi(x, n/2), n > 0;
1.0 / (sqrt(x) * powi(x, abs(n/2))), n < 0. 1.0 / (sqrt(x) * powi(x, abs(n/2))), n < 0.
...@@ -1230,10 +1232,13 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc, ...@@ -1230,10 +1232,13 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
real_arithmetic (&c2, MULT_EXPR, &c, &dconst2); real_arithmetic (&c2, MULT_EXPR, &c, &dconst2);
n = real_to_integer (&c2); n = real_to_integer (&c2);
real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0); real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);
c2_is_int = real_identical (&c2, &cint);
if (flag_unsafe_math_optimizations if (flag_unsafe_math_optimizations
&& sqrtfn && sqrtfn
&& real_identical (&c2, &cint)) && c2_is_int
&& !c_is_int
&& optimize_function_for_speed_p (cfun))
{ {
tree powi_x_ndiv2 = NULL_TREE; tree powi_x_ndiv2 = NULL_TREE;
...@@ -1286,6 +1291,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc, ...@@ -1286,6 +1291,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
&& cbrtfn && cbrtfn
&& (gimple_val_nonnegative_real_p (arg0) || !HONOR_NANS (mode)) && (gimple_val_nonnegative_real_p (arg0) || !HONOR_NANS (mode))
&& real_identical (&c2, &c) && real_identical (&c2, &c)
&& !c2_is_int
&& optimize_function_for_speed_p (cfun) && optimize_function_for_speed_p (cfun)
&& powi_cost (n / 3) <= POWI_MAX_MULTS) && powi_cost (n / 3) <= POWI_MAX_MULTS)
{ {
......
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