aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2009-08-18 13:40:18 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2009-08-18 13:40:18 +0000
commit776e7174167360fdf2ba990e7c7c22536fe9227a (patch)
tree352c74ccff21f703c3493cc20f89542a38b26f32 /gcc/builtins.c
parentf3252b3c18e688f43df708d0003f0b6e0f89cc17 (diff)
downloadgcc-776e7174167360fdf2ba990e7c7c22536fe9227a.zip
gcc-776e7174167360fdf2ba990e7c7c22536fe9227a.tar.gz
gcc-776e7174167360fdf2ba990e7c7c22536fe9227a.tar.bz2
re PR middle-end/41094 (Erroneous optimization of pow() with -ffast-math)
2009-08-18 Richard Guenther <rguenther@suse.de> PR middle-end/41094 * builtins.c (fold_builtin_pow): Fold pow(pow(x,y),z) to pow(x,y*z) only if x is nonnegative. * gcc.dg/torture/pr41094.c: New testcase. * gcc.dg/torture/builtin-power-1.c: Adjust. * gcc.dg/builtins-10.c: Likewise. From-SVN: r150874
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 025c169..1a9e966 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -8737,15 +8737,18 @@ fold_builtin_pow (location_t loc, tree fndecl, tree arg0, tree arg1, tree type)
}
}
- /* Optimize pow(pow(x,y),z) = pow(x,y*z). */
+ /* Optimize pow(pow(x,y),z) = pow(x,y*z) iff x is nonnegative. */
if (fcode == BUILT_IN_POW
|| fcode == BUILT_IN_POWF
|| fcode == BUILT_IN_POWL)
{
tree arg00 = CALL_EXPR_ARG (arg0, 0);
- tree arg01 = CALL_EXPR_ARG (arg0, 1);
- tree narg1 = fold_build2_loc (loc, MULT_EXPR, type, arg01, arg1);
- return build_call_expr_loc (loc, fndecl, 2, arg00, narg1);
+ if (tree_expr_nonnegative_p (arg00))
+ {
+ tree arg01 = CALL_EXPR_ARG (arg0, 1);
+ tree narg1 = fold_build2_loc (loc, MULT_EXPR, type, arg01, arg1);
+ return build_call_expr_loc (loc, fndecl, 2, arg00, narg1);
+ }
}
}