From: Michael Matz Date: Thu, 18 Mar 2010 16:07:53 +0000 (+0000) Subject: re PR middle-end/43419 (gcc replaces pow(x, 0.5) by sqrt(x), invalid when x is -0) X-Git-Tag: upstream/12.2.0~94189 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c21372c41eb1f5995048a67bfc9512d860c986cb;p=platform%2Fupstream%2Fgcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4254a8..31b4340 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-03-18 Michael Matz + + 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 Eric Botcazou diff --git a/gcc/builtins.c b/gcc/builtins.c index 1e089ef9..705a255 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4b69cb7..4a0ef16 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-03-18 Michael Matz + + PR middle-end/43419 + * gcc.dg/pr43419.c: New testcase. + 2010-03-18 H.J. Lu PR rtl-optimization/43360 @@ -16,10 +21,10 @@ 2010-03-17 Jerry DeLisle PR libfortran/43265 - *gfortran.dg/read_empty_file.f: New test. - *gfortran.dg/read_eof_all.f90: New test. - *gfortran.dg/namelist_27.f90: Eliminate infinite loop posibility. - *gfortran.dg/namelist_28.f90: Eliminate infinite loop posibility. + * gfortran.dg/read_empty_file.f: New test. + * gfortran.dg/read_eof_all.f90: New test. + * gfortran.dg/namelist_27.f90: Eliminate infinite loop posibility. + * gfortran.dg/namelist_28.f90: Eliminate infinite loop posibility. 2010-03-17 Michael Matz diff --git a/gcc/testsuite/gcc.dg/pr43419.c b/gcc/testsuite/gcc.dg/pr43419.c new file mode 100644 index 0000000..a4306f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr43419.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-options "-O1" } */ +/* { dg-add-options ieee } */ +#include + +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; +}