public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/18589] New: could optimize FP multiplies better
@ 2004-11-21 9:28 debian-gcc at lists dot debian dot org
2004-11-21 14:24 ` [Bug target/18589] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: debian-gcc at lists dot debian dot org @ 2004-11-21 9:28 UTC (permalink / raw)
To: gcc-bugs
[forwarded from http://bugs.debian.org/268115]
Matthias
The bug submitter writes:
compiling this function:
double baz(double foo, double bar)
{
return foo*foo*foo*foo*bar*bar*bar*bar;
}
on amd64 with -O6 -ffast-math, gcc emits this code:
foo.o: file format elf64-x86-64
Disassembly of section .text:
... (some similar functions that I was messing around with) ...
0000000000000050 <ddbar>:
50: f2 0f 59 c0 mulsd %xmm0,%xmm0
54: f2 0f 59 c0 mulsd %xmm0,%xmm0
58: f2 0f 59 c1 mulsd %xmm1,%xmm0
5c: f2 0f 59 c1 mulsd %xmm1,%xmm0
60: f2 0f 59 c1 mulsd %xmm1,%xmm0
64: f2 0f 59 c1 mulsd %xmm1,%xmm0
68: c3 retq
So, it notices that it can do foo*foo*foo*foo with two mulsd instructions,
but it misses the same optimization for bar*bar*bar*bar. It would save one
FP multiply overall to do:
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
mulsd %xmm1, %xmm0
retq
Also, the two non-dependent muls could run in parallel.
Without -ffast-math, of course, gcc can't take advantage of the laws of
arithmetic like that and has to do all the multiplies the straightforward
way.
--
Summary: could optimize FP multiplies better
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: debian-gcc at lists dot debian dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: amd64-linux
GCC host triplet: amd64-linux
GCC target triplet: amd64-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <bug-18589-5724@http.gcc.gnu.org/bugzilla/>]
[parent not found: <bug-18589-4@http.gcc.gnu.org/bugzilla/>]
* [Bug tree-optimization/18589] could optimize FP multiplies better
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
@ 2012-01-05 23:07 ` pinskia at gcc dot gnu.org
2012-01-09 12:21 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-05 23:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2005-12-21 03:49:53 |2012-01-04
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-05 23:06:56 UTC ---
The tree level on the trunk we get:
powmult.2_10 = foo_1(D) * foo_1(D);
D.1709_4 = bar_3(D) * bar_3(D);
D.1710_5 = D.1709_4 * bar_3(D);
D.1711_6 = D.1710_5 * bar_3(D);
powmult.2_9 = D.1711_6 * powmult.2_10;
D.1707_7 = powmult.2_9 * powmult.2_10;
--- CUT ---
which is just as bad.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/18589] could optimize FP multiplies better
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
2012-01-05 23:07 ` pinskia at gcc dot gnu.org
@ 2012-01-09 12:21 ` rguenth at gcc dot gnu.org
2012-01-09 13:09 ` wschmidt at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-01-09 12:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu.org,
| |wschmidt at gcc dot gnu.org
--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-09 12:20:31 UTC ---
Yeah, reassoc does not canonicalize to pow () so the tree level optimal
expansion does not trigger [in reality reassoc should probably do both
on-the-fly - linearly expand existing pow()s to expose them to multiply
chains and sorting, combine them back and then emit them in optimal form].
Bill, something you want to tackle?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/18589] could optimize FP multiplies better
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
2012-01-05 23:07 ` pinskia at gcc dot gnu.org
2012-01-09 12:21 ` rguenth at gcc dot gnu.org
@ 2012-01-09 13:09 ` wschmidt at gcc dot gnu.org
2012-01-13 22:37 ` wschmidt at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2012-01-09 13:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
--- Comment #7 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2012-01-09 13:06:34 UTC ---
Sure, I'll at least have a look at it when I get some time.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/18589] could optimize FP multiplies better
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2012-01-09 13:09 ` wschmidt at gcc dot gnu.org
@ 2012-01-13 22:37 ` wschmidt at gcc dot gnu.org
2012-04-12 16:15 ` wschmidt at gcc dot gnu.org
2012-04-12 16:18 ` wschmidt at gcc dot gnu.org
5 siblings, 0 replies; 11+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2012-01-13 22:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
William J. Schmidt <wschmidt at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |wschmidt at gcc dot gnu.org
|gnu.org |
Target Milestone|--- |4.8.0
--- Comment #8 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2012-01-13 22:27:48 UTC ---
I've started to look at this -- I'll plan to get a patch in place for 4.8.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/18589] could optimize FP multiplies better
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2012-01-13 22:37 ` wschmidt at gcc dot gnu.org
@ 2012-04-12 16:15 ` wschmidt at gcc dot gnu.org
2012-04-12 16:18 ` wschmidt at gcc dot gnu.org
5 siblings, 0 replies; 11+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2012-04-12 16:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
--- Comment #9 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2012-04-12 16:15:24 UTC ---
Author: wschmidt
Date: Thu Apr 12 16:15:13 2012
New Revision: 186384
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186384
Log:
gcc:
2012-04-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
PR tree-optimization/18589
* tree-ssa-reassoc.c (reassociate_stats): Add two fields.
(operand_entry): Add count field.
(add_repeat_to_ops_vec): New function.
(completely_remove_stmt): Likewise.
(remove_def_if_absorbed_call): Likewise.
(remove_visited_stmt_chain): Remove feeding builtin pow/powi calls.
(acceptable_pow_call): New function.
(linearize_expr_tree): Look for builtin pow/powi calls and add operand
entries with repeat counts when found.
(repeat_factor_d): New struct and associated typedefs.
(repeat_factor_vec): New static vector variable.
(compare_repeat_factors): New function.
(get_reassoc_pow_ssa_name): Likewise.
(attempt_builtin_powi): Likewise.
(reassociate_bb): Call attempt_builtin_powi.
(fini_reassoc): Two new calls to statistics_counter_event.
gcc/testsuite:
2012-04-12 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
PR tree-optimization/18589
* gcc.dg/tree-ssa/pr18589-1.c: New test.
* gcc.dg/tree-ssa/pr18589-2.c: Likewise.
* gcc.dg/tree-ssa/pr18589-3.c: Likewise.
* gcc.dg/tree-ssa/pr18589-4.c: Likewise.
* gcc.dg/tree-ssa/pr18589-5.c: Likewise.
* gcc.dg/tree-ssa/pr18589-6.c: Likewise.
* gcc.dg/tree-ssa/pr18589-7.c: Likewise.
* gcc.dg/tree-ssa/pr18589-8.c: Likewise.
* gcc.dg/tree-ssa/pr18589-9.c: Likewise.
* gcc.dg/tree-ssa/pr18589-10.c: Likewise.
Added:
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-1.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-10.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-2.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-3.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-4.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-5.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-6.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-7.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-8.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/pr18589-9.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-reassoc.c
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/18589] could optimize FP multiplies better
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2012-04-12 16:15 ` wschmidt at gcc dot gnu.org
@ 2012-04-12 16:18 ` wschmidt at gcc dot gnu.org
5 siblings, 0 replies; 11+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2012-04-12 16:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18589
William J. Schmidt <wschmidt at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #10 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2012-04-12 16:16:50 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-04-12 16:18 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-21 9:28 [Bug target/18589] New: could optimize FP multiplies better debian-gcc at lists dot debian dot org
2004-11-21 14:24 ` [Bug target/18589] " pinskia at gcc dot gnu dot org
2005-01-12 6:50 ` [Bug tree-optimization/18589] " pinskia at gcc dot gnu dot org
2005-07-05 19:37 ` pinskia at gcc dot gnu dot org
[not found] <bug-18589-5724@http.gcc.gnu.org/bugzilla/>
2006-03-05 17:43 ` pinskia at gcc dot gnu dot org
[not found] <bug-18589-4@http.gcc.gnu.org/bugzilla/>
2012-01-05 23:07 ` pinskia at gcc dot gnu.org
2012-01-09 12:21 ` rguenth at gcc dot gnu.org
2012-01-09 13:09 ` wschmidt at gcc dot gnu.org
2012-01-13 22:37 ` wschmidt at gcc dot gnu.org
2012-04-12 16:15 ` wschmidt at gcc dot gnu.org
2012-04-12 16:18 ` wschmidt 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).