re PR middle-end/43419 (gcc replaces pow(x, 0.5) by sqrt(x), invalid when x is -0)

PR middle-end/43419
	* builtins.c (expand_builtin_pow): Don't transform pow(x, 0.5)
	into sqrt(x) if we need to preserve signed zeros.

testsuite/
	* gcc.dg/pr43419.c: New testcase.

From-SVN: r157543
This commit is contained in:
Michael Matz 2010-03-18 16:07:53 +00:00
parent 82fa5f8aa7
commit c21372c41e
4 changed files with 38 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2010-03-18 Michael Matz <matz@suse.de>
PR middle-end/43419
* builtins.c (expand_builtin_pow): Don't transform pow(x, 0.5)
into sqrt(x) if we need to preserve signed zeros.
2010-03-18 Steven Bosscher <steven@gcc.gnu.org>
Eric Botcazou <ebotcazou@adacore.com>

View File

@ -2980,7 +2980,10 @@ expand_builtin_pow (tree exp, rtx target, rtx subtarget)
&& ((flag_unsafe_math_optimizations
&& optimize_insn_for_speed_p ()
&& powi_cost (n/2) <= POWI_MAX_MULTS)
|| n == 1))
/* Even the c==0.5 case cannot be done unconditionally
when we need to preserve signed zeros, as
pow (-0, 0.5) is +0, while sqrt(-0) is -0. */
|| (!HONOR_SIGNED_ZEROS (mode) && n == 1)))
{
tree call_expr = build_call_nofold (fn, 1, narg0);
/* Use expand_expr in case the newly built call expression

View File

@ -1,3 +1,8 @@
2010-03-18 Michael Matz <matz@suse.de>
PR middle-end/43419
* gcc.dg/pr43419.c: New testcase.
2010-03-18 H.J. Lu <hongjiu.lu@intel.com>
PR rtl-optimization/43360

View File

@ -0,0 +1,19 @@
/* { dg-do run } */
/* { dg-options "-O1" } */
/* { dg-add-options ieee } */
#include <math.h>
extern void abort (void);
void __attribute__((noinline)) f (double x)
{
double pluszero = pow (x, 0.5);
double minuszero = sqrt (x);
if (signbit (pluszero) == signbit (minuszero))
abort ();
}
int main(void)
{
f (-0.0);
return 0;
}