public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math
@ 2009-08-17 18:03 warp at iki dot fi
2009-08-17 18:38 ` [Bug c++/41094] " paolo dot carlini at oracle dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: warp at iki dot fi @ 2009-08-17 18:03 UTC (permalink / raw)
To: gcc-bugs
Consider the following program:
//----------------------------------------------------------------------
#include <iostream>
#include <cmath>
int main()
{
for(double p = .25; p <= .5; p += .25)
for(double x = -10.0; x <= 10.0; x += 20.0)
{
std::cout
<< "\nx*x = " << x*x
<< "\npow(100, " << p << ") = " << std::pow(100.0, p)
<< "\npow(x*x, " << p << ") = " << std::pow(x*x, p)
<< "\n";
}
}
//----------------------------------------------------------------------
When compiling without -ffast-math, the output is the expected one.
However, if compiled with -ffast-math (other optimization options don't
seem to matter), it produces incorrectly "nan" and "-10" for the third
line ("std::pow(x*x, p") when 'x' is negative.
If the -fno-unsafe-math-optimizations option is specified in addition
to -ffast-math, the bug is not triggered.
If "double xx = x*x;" is added inside the loop and then 'xx' is used
instead of 'x*x', the bug is not triggered either.
--
Summary: Erroneous optimization of pow() with -ffast-math
Product: gcc
Version: 4.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: warp at iki dot fi
GCC build triplet: i586-suse-linux
GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/41094] Erroneous optimization of pow() with -ffast-math
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
@ 2009-08-17 18:38 ` paolo dot carlini at oracle dot com
2009-08-18 9:20 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-08-17 18:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from paolo dot carlini at oracle dot com 2009-08-17 18:38 -------
Note, this isn't C++ specific:
int main()
{
double x = -10.0;
__builtin_printf("%g\n", __builtin_pow(x * x, 0.25));
}
Richard, can you have a look? It's hot here ;) but first blush I don't see why
fast-math is so special here...
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/41094] Erroneous optimization of pow() with -ffast-math
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
2009-08-17 18:38 ` [Bug c++/41094] " paolo dot carlini at oracle dot com
@ 2009-08-18 9:20 ` rguenth at gcc dot gnu dot org
2009-08-18 13:40 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-18 9:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2009-08-18 09:20 -------
Looks like a bug in fold.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |rguenth at gcc dot gnu dot
|dot org |org
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2009-08-18 09:20:14
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/41094] Erroneous optimization of pow() with -ffast-math
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
2009-08-17 18:38 ` [Bug c++/41094] " paolo dot carlini at oracle dot com
2009-08-18 9:20 ` rguenth at gcc dot gnu dot org
@ 2009-08-18 13:40 ` rguenth at gcc dot gnu dot org
2009-08-24 9:52 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-18 13:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2009-08-18 13:40 -------
Subject: Bug 41094
Author: rguenth
Date: Tue Aug 18 13:40:18 2009
New Revision: 150874
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150874
Log:
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.
Added:
trunk/gcc/testsuite/gcc.dg/torture/pr41094.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/builtins-10.c
trunk/gcc/testsuite/gcc.dg/torture/builtin-power-1.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/41094] Erroneous optimization of pow() with -ffast-math
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
` (2 preceding siblings ...)
2009-08-18 13:40 ` rguenth at gcc dot gnu dot org
@ 2009-08-24 9:52 ` rguenth at gcc dot gnu dot org
2009-08-24 9:56 ` rguenth at gcc dot gnu dot org
2009-08-24 10:03 ` rguenth at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-24 9:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2009-08-24 09:52 -------
Subject: Bug 41094
Author: rguenth
Date: Mon Aug 24 09:52:03 2009
New Revision: 151051
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151051
Log:
2009-08-24 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.
Added:
branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/pr41094.c
Modified:
branches/gcc-4_4-branch/gcc/ChangeLog
branches/gcc-4_4-branch/gcc/builtins.c
branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/builtins-10.c
branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/torture/builtin-power-1.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/41094] Erroneous optimization of pow() with -ffast-math
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
` (3 preceding siblings ...)
2009-08-24 9:52 ` rguenth at gcc dot gnu dot org
@ 2009-08-24 9:56 ` rguenth at gcc dot gnu dot org
2009-08-24 10:03 ` rguenth at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-24 9:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from rguenth at gcc dot gnu dot org 2009-08-24 09:56 -------
Subject: Bug 41094
Author: rguenth
Date: Mon Aug 24 09:56:30 2009
New Revision: 151052
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151052
Log:
2009-08-24 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.
Added:
branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/torture/pr41094.c
Modified:
branches/gcc-4_3-branch/gcc/ChangeLog
branches/gcc-4_3-branch/gcc/builtins.c
branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/builtins-10.c
branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/torture/builtin-power-1.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/41094] Erroneous optimization of pow() with -ffast-math
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
` (4 preceding siblings ...)
2009-08-24 9:56 ` rguenth at gcc dot gnu dot org
@ 2009-08-24 10:03 ` rguenth at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-24 10:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rguenth at gcc dot gnu dot org 2009-08-24 10:03 -------
Fixed.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Known to fail| |4.3.4 4.4.1
Known to work| |4.3.5 4.4.2 4.5.0
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41094
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-08-24 10:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-17 18:03 [Bug c++/41094] New: Erroneous optimization of pow() with -ffast-math warp at iki dot fi
2009-08-17 18:38 ` [Bug c++/41094] " paolo dot carlini at oracle dot com
2009-08-18 9:20 ` rguenth at gcc dot gnu dot org
2009-08-18 13:40 ` rguenth at gcc dot gnu dot org
2009-08-24 9:52 ` rguenth at gcc dot gnu dot org
2009-08-24 9:56 ` rguenth at gcc dot gnu dot org
2009-08-24 10:03 ` rguenth at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).