public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
@ 2010-01-11 21:40 meissner at gcc dot gnu dot org
2010-01-11 21:42 ` [Bug rtl-optimization/42694] " meissner at gcc dot gnu dot org
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: meissner at gcc dot gnu dot org @ 2010-01-11 21:40 UTC (permalink / raw)
To: gcc-bugs
Right now, the compiler has no special code to optimize pow (x, 0.75) into
something like sqrt (x) * sqrt (sqrt (x)) under -ffast-math, nor pow (x, 0.25)
into sqrt (sqrt (x)). On machines with a builtin sqrt instruction, it is often
times faster to do the calculations using sqrt than calling the pow function.
In particular, x**0.75 shows up in the bwaves spec 2006 benchmark.
For sqrt (sqrt (x)) vs pow (x, 0.25), I see:
IBM power6: 9.2 times faster
Intel core2 laptop: 5 times faster
AMD K8 system: 3.2 times faster
For sqrt (x) * sqrt (sqrt (x)) vs. pow (x, 0.75), I see:
IBM power6: 6.1 times faster
Intel core2 laptop: 3.4 times faster
AMD K8 system: 2.3 times faster
In addition, the compiler optimizes sqrt (sqrt (x)) into pow (x, 0.25), and
similar optimizations.
This should be fixed by adding a hook to say what the relative speed of sqrt
and cbrt vs. pow, so that the backend can control whether or not this
optimization should be done. By default, the optimization is probably only
useful if -Os is used on machines that have a hardware sqrt instruction.
--
Summary: Compiler could optimize pow (x, 0.75) into sqrt (x) *
sqrt (sqrt (x))
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: meissner at gcc dot gnu dot org
ReportedBy: meissner at gcc dot gnu dot org
GCC build triplet: powerpc64-unknown-linux-gnu
GCC host triplet: powerpc64-unknown-linux-gnu
GCC target triplet: powerpc64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
@ 2010-01-11 21:42 ` meissner at gcc dot gnu dot org
2010-01-12 9:08 ` [Bug middle-end/42694] " rguenth at gcc dot gnu dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: meissner at gcc dot gnu dot org @ 2010-01-11 21:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from meissner at gcc dot gnu dot org 2010-01-11 21:42 -------
Created an attachment (id=19542)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19542&action=view)
Program to demonstrate the slowdown
This program calculates the speed of various pow arguments.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
2010-01-11 21:42 ` [Bug rtl-optimization/42694] " meissner at gcc dot gnu dot org
@ 2010-01-12 9:08 ` rguenth at gcc dot gnu dot org
2010-01-26 0:40 ` meissner at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-12 9:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2010-01-12 09:08 -------
Confirmed and easy to add in the pow expander (expand_builtin_pow).
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Component|rtl-optimization |middle-end
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2010-01-12 09:08:00
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
2010-01-11 21:42 ` [Bug rtl-optimization/42694] " meissner at gcc dot gnu dot org
2010-01-12 9:08 ` [Bug middle-end/42694] " rguenth at gcc dot gnu dot org
@ 2010-01-26 0:40 ` meissner at gcc dot gnu dot org
2010-01-26 9:57 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: meissner at gcc dot gnu dot org @ 2010-01-26 0:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from meissner at gcc dot gnu dot org 2010-01-26 00:40 -------
Created an attachment (id=19706)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19706&action=view)
Proposed patch to fix the problem
Patch to add 3 new switches to tune whether to use a combination of sqrt/cbrt
to replace pow.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
` (2 preceding siblings ...)
2010-01-26 0:40 ` meissner at gcc dot gnu dot org
@ 2010-01-26 9:57 ` rguenth at gcc dot gnu dot org
2010-01-26 10:03 ` paolo dot carlini at oracle dot com
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-26 9:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2010-01-26 09:57 -------
Ugh, I don't like more switches. Instead I would say that using two sqrt
calls instead of one pow call is always profitable if not optimizing for size
and the target has an optab for sqrt.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
` (3 preceding siblings ...)
2010-01-26 9:57 ` rguenth at gcc dot gnu dot org
@ 2010-01-26 10:03 ` paolo dot carlini at oracle dot com
2010-04-14 15:02 ` meissner at gcc dot gnu dot org
2010-04-14 15:03 ` meissner at gcc dot gnu dot org
6 siblings, 0 replies; 10+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-01-26 10:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from paolo dot carlini at oracle dot com 2010-01-26 10:03 -------
With my "user of the compiler" hat, I must say that I was also put off by the 3
new switches... fwiw
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
` (4 preceding siblings ...)
2010-01-26 10:03 ` paolo dot carlini at oracle dot com
@ 2010-04-14 15:02 ` meissner at gcc dot gnu dot org
2010-04-14 15:03 ` meissner at gcc dot gnu dot org
6 siblings, 0 replies; 10+ messages in thread
From: meissner at gcc dot gnu dot org @ 2010-04-14 15:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from meissner at gcc dot gnu dot org 2010-04-14 15:02 -------
Subject: Bug 42694
Author: meissner
Date: Wed Apr 14 15:01:40 2010
New Revision: 158346
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158346
Log:
PR 42694: Optimize pow (x, 0.25), pow (x, 0.75), pow (x, 1./6.)
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
` (5 preceding siblings ...)
2010-04-14 15:02 ` meissner at gcc dot gnu dot org
@ 2010-04-14 15:03 ` meissner at gcc dot gnu dot org
6 siblings, 0 replies; 10+ messages in thread
From: meissner at gcc dot gnu dot org @ 2010-04-14 15:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from meissner at gcc dot gnu dot org 2010-04-14 15:03 -------
Fixed with subversion id 158346.
--
meissner at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
[not found] <bug-42694-4@http.gcc.gnu.org/bugzilla/>
2010-12-07 17:42 ` meissner at gcc dot gnu.org
@ 2010-12-08 16:34 ` meissner at gcc dot gnu.org
1 sibling, 0 replies; 10+ messages in thread
From: meissner at gcc dot gnu.org @ 2010-12-08 16:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
--- Comment #9 from Michael Meissner <meissner at gcc dot gnu.org> 2010-12-08 16:34:26 UTC ---
Author: meissner
Date: Wed Dec 8 16:34:20 2010
New Revision: 167594
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167594
Log:
PR 42694: add checks to make sure sqrt is supported
Added:
trunk/gcc/testsuite/gcc.target/powerpc/ppc-pow.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/42694] Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x))
[not found] <bug-42694-4@http.gcc.gnu.org/bugzilla/>
@ 2010-12-07 17:42 ` meissner at gcc dot gnu.org
2010-12-08 16:34 ` meissner at gcc dot gnu.org
1 sibling, 0 replies; 10+ messages in thread
From: meissner at gcc dot gnu.org @ 2010-12-07 17:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42694
--- Comment #8 from Michael Meissner <meissner at gcc dot gnu.org> 2010-12-07 17:42:04 UTC ---
Created attachment 22675
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22675
Add check for sqrt optab being present before doing some optimizations
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2010-12-08 16:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-11 21:40 [Bug rtl-optimization/42694] New: Compiler could optimize pow (x, 0.75) into sqrt (x) * sqrt (sqrt (x)) meissner at gcc dot gnu dot org
2010-01-11 21:42 ` [Bug rtl-optimization/42694] " meissner at gcc dot gnu dot org
2010-01-12 9:08 ` [Bug middle-end/42694] " rguenth at gcc dot gnu dot org
2010-01-26 0:40 ` meissner at gcc dot gnu dot org
2010-01-26 9:57 ` rguenth at gcc dot gnu dot org
2010-01-26 10:03 ` paolo dot carlini at oracle dot com
2010-04-14 15:02 ` meissner at gcc dot gnu dot org
2010-04-14 15:03 ` meissner at gcc dot gnu dot org
[not found] <bug-42694-4@http.gcc.gnu.org/bugzilla/>
2010-12-07 17:42 ` meissner at gcc dot gnu.org
2010-12-08 16:34 ` meissner at gcc dot gnu.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).