public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better
@ 2003-07-27 5:13 dbaron at dbaron dot org
2003-07-27 5:16 ` [Bug c++/11680] " dbaron at dbaron dot org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: dbaron at dbaron dot org @ 2003-07-27 5:13 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
Summary: member access of C++ class with all methods inline
should be optimized better
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dbaron at dbaron dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
This is a reduced testcase of the problem described in
http://bugzilla.mozilla.org/show_bug.cgi?id=206682#c25 , being filed as
mentioned in bug 11376 comment 6 and bug 11376 comment 37. The bug is that gcc
didn't optimize the code in question as well as I think in should. (Optimizing
code written in a "generic programming" style is needed to encourage people to
write such code...) In particular, I was working on a class that did UTF-16 to
UTF-8 conversion (and could be used as one of many character sinks with
Mozilla's string classes).
In particular, the code involved a large inline method that involved repeated
use of a member variable (being used as a cursor into the output buffer being
written). (By default, gcc didn't inline the method. This was hand-optimized
by using |__attribute__((always_inline))|. Should I file a separate bug on
this, or is it unlikely to be fixed?) Once the method was inlined, gcc did not
optimize the use of the member variable as well as it could have. This was
hand-optimized by assigning from the member variable at the beginning of the
|write| function and assigning back to it at the end. Since all the methods of
the class are inlined and the compiler can tell that a pointer to the member
variable |mBuffer| is never taken, gcc should have been able to produce code
that was just as fast with or without this second hand-optimization.
This can be tested by comparing the performance of the attached testcase with
the arguments "slow" (forced inline, but without the local variable
hand-optimization) and "fast" (with the local variable hand-optimization). I
claim that gcc should be producing essentially identical code for these two
cases, so they should perform equivalently. This is not the case:
> /usr/local/gcc-trunk/bin/g++ -O2 perf.cpp
> time ./a.out fast
1.270u 0.010s 0:01.24 103.2% 0+0k 0+0io 224pf+0w
> time ./a.out fast
1.270u 0.000s 0:01.25 101.6% 0+0k 0+0io 224pf+0w
> time ./a.out fast
1.300u 0.010s 0:01.27 103.1% 0+0k 0+0io 224pf+0w
> time ./a.out slow
4.030u 0.010s 0:04.03 100.2% 0+0k 0+0io 224pf+0w
> time ./a.out slow
4.030u 0.000s 0:04.11 98.0% 0+0k 0+0io 224pf+0w
> time ./a.out slow
4.060u 0.000s 0:04.10 99.0% 0+0k 0+0io 224pf+0w
These measurements were made with the gcc trunk as of today. The numbers for
the gcc 3.3 release are similar (although gcc 3.3 was slightly slower for the
"fast" version and slightly faster for the "slow" version).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
@ 2003-07-27 5:16 ` dbaron at dbaron dot org
2003-07-27 5:31 ` [Bug optimization/11680] " pinskia at physics dot uc dot edu
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dbaron at dbaron dot org @ 2003-07-27 5:16 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
------- Additional Comments From dbaron at dbaron dot org 2003-07-27 05:16 -------
Created an attachment (id=4487)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4487&action=view)
test program
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
2003-07-27 5:16 ` [Bug c++/11680] " dbaron at dbaron dot org
@ 2003-07-27 5:31 ` pinskia at physics dot uc dot edu
2003-07-27 5:33 ` dberlin at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-07-27 5:31 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
pinskia at physics dot uc dot edu changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Component|c++ |optimization
Ever Confirmed| |1
GCC build triplet|i686-pc-linux-gnu |
GCC host triplet|i686-pc-linux-gnu |
GCC target triplet|i686-pc-linux-gnu |*-*-*
Keywords| |pessimizes-code
Priority|P2 |P3
Last reconfirmed|0000-00-00 00:00:00 |2003-07-27 05:31:00
date| |
------- Additional Comments From pinskia at physics dot uc dot edu 2003-07-27 05:31 -------
I can confirm this on the mainline (20030726) on powerpc-apple-darwin6.6 on a powerpc 750.
The problem is that are large number of stores in the loop which is redudent which might be able
to fixed by store motion but are not.
On the mainline, GCC inlines the method so there is no need for always_inline any more.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
2003-07-27 5:16 ` [Bug c++/11680] " dbaron at dbaron dot org
2003-07-27 5:31 ` [Bug optimization/11680] " pinskia at physics dot uc dot edu
@ 2003-07-27 5:33 ` dberlin at gcc dot gnu dot org
2003-07-27 9:34 ` gdr at integrable-solutions dot net
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dberlin at gcc dot gnu dot org @ 2003-07-27 5:33 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
------- Additional Comments From dberlin at gcc dot gnu dot org 2003-07-27 05:33 -------
Try the tree-ssa branch, which should and does help quite a lot for these types of problems
My numbers:
mainline:
[dberlin@dberlin dberlin]$ time ./a.out slow
real 0m3.777s
user 0m3.770s
sys 0m0.010s
[dberlin@dberlin dberlin]$ time ./a.out fast
real 0m1.065s
user 0m1.070s
sys 0m0.000s
tree-ssa:
[dberlin@dberlin dberlin]$ time ./a.out slow
real 0m1.356s
user 0m1.360s
sys 0m0.000s
[dberlin@dberlin dberlin]$ time ./a.out fast
real 0m1.120s
user 0m1.110s
sys 0m0.010s
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (2 preceding siblings ...)
2003-07-27 5:33 ` dberlin at gcc dot gnu dot org
@ 2003-07-27 9:34 ` gdr at integrable-solutions dot net
2003-08-23 1:56 ` dhazeghi at yahoo dot com
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gdr at integrable-solutions dot net @ 2003-07-27 9:34 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
------- Additional Comments From gdr at integrable-solutions dot net 2003-07-27 09:34 -------
Subject: Re: New: member access of C++ class with all methods inline should be optimized better
"dbaron at dbaron dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| In particular, the code involved a large inline method that involved repeated
| use of a member variable (being used as a cursor into the output buffer being
| written). (By default, gcc didn't inline the method. This was hand-optimized
| by using |__attribute__((always_inline))|. Should I file a separate bug on
| this, or is it unlikely to be fixed?)
Please fill a bug report. GCC should implement the obvious and original
meaning of "inline". That it failed is a bug.
That one should ressort to contorsions and unspeakable syntax like
__attribute__((always_inline)) while we have the obivous syntax is
also a bug.
-- Gaby
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (3 preceding siblings ...)
2003-07-27 9:34 ` gdr at integrable-solutions dot net
@ 2003-08-23 1:56 ` dhazeghi at yahoo dot com
2003-09-08 23:01 ` dbaron at dbaron dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dhazeghi at yahoo dot com @ 2003-08-23 1:56 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
dhazeghi at yahoo dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
GCC target triplet|*-*-* |
Target Milestone|3.4 |---
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (4 preceding siblings ...)
2003-08-23 1:56 ` dhazeghi at yahoo dot com
@ 2003-09-08 23:01 ` dbaron at dbaron dot org
2003-11-27 7:32 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: dbaron at dbaron dot org @ 2003-09-08 23:01 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
------- Additional Comments From dbaron at dbaron dot org 2003-09-08 23:01 -------
Re comment 3: That's good to see. However, I would think that there should be
an optimization (really application of existing optimizations to this case) that
would cause the generated code to be exactly the same. That was my hope when
filing this bug. (After all, making clearer code run slower discourages clear
code.)
Re comment 4: Filed as bug 12219.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (5 preceding siblings ...)
2003-09-08 23:01 ` dbaron at dbaron dot org
@ 2003-11-27 7:32 ` pinskia at gcc dot gnu dot org
2004-03-03 7:10 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-27 7:32 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-11-27 07:32 -------
Suspending this one as it is fixed on the tree-ssa (might even be better than quoted now).
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |SUSPENDED
Target Milestone|--- |tree-ssa
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (6 preceding siblings ...)
2003-11-27 7:32 ` pinskia at gcc dot gnu dot org
@ 2004-03-03 7:10 ` pinskia at gcc dot gnu dot org
2004-05-26 22:37 ` [Bug rtl-optimization/11680] " pinskia at gcc dot gnu dot org
2004-06-03 4:42 ` pinskia at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-03 7:10 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-03-03 07:10 -------
GCC mainline:
zhivago2:gcc/objdir_c/gcc] pinskia% time ./a.out slow
4.510u 0.000s 0:04.59 98.2% 0+0k 0+0io 0pf+0w
[zhivago2:gcc/objdir_c/gcc] pinskia% time ./a.out fast
3.560u 0.010s 0:03.91 91.3% 0+0k 0+0io 0pf+0w
[zhivago2:gcc/objdir_c/gcc] pinskia% time ./a.out original
4.010u 0.010s 0:04.42 90.9% 0+0k 0+0io 0pf+0w
TREE-SSA:
[zhivago2:gcc/objdir_c/gcc] pinskia% time ./a.out original
3.350u 0.010s 0:03.50 96.0% 0+0k 0+1io 0pf+0w
[zhivago2:gcc/objdir_c/gcc] pinskia% time ./a.out fast
3.620u 0.020s 0:04.62 78.7% 0+0k 0+0io 0pf+0w
[zhivago2:gcc/objdir_c/gcc] pinskia% time ./a.out slow
3.610u 0.000s 0:03.73 96.7% 0+0k 0+0io 0pf+0w
Either it is already fixed on the mainline or the tree-ssa needs improvements.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|SUSPENDED |NEW
Last reconfirmed|2003-07-27 05:31:00 |2004-03-03 07:10:01
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (7 preceding siblings ...)
2004-03-03 7:10 ` pinskia at gcc dot gnu dot org
@ 2004-05-26 22:37 ` pinskia at gcc dot gnu dot org
2004-06-03 4:42 ` pinskia at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-26 22:37 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.5.0 |---
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug rtl-optimization/11680] member access of C++ class with all methods inline should be optimized better
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
` (8 preceding siblings ...)
2004-05-26 22:37 ` [Bug rtl-optimization/11680] " pinskia at gcc dot gnu dot org
@ 2004-06-03 4:42 ` pinskia at gcc dot gnu dot org
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-03 4:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-03 04:42 -------
This was fixed in the merging of the tree-ssa, all the asm of the different ways are exactly the same
now (and better than the 3.4.0 also).
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |3.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11680
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-06-03 4:42 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-27 5:13 [Bug c++/11680] New: member access of C++ class with all methods inline should be optimized better dbaron at dbaron dot org
2003-07-27 5:16 ` [Bug c++/11680] " dbaron at dbaron dot org
2003-07-27 5:31 ` [Bug optimization/11680] " pinskia at physics dot uc dot edu
2003-07-27 5:33 ` dberlin at gcc dot gnu dot org
2003-07-27 9:34 ` gdr at integrable-solutions dot net
2003-08-23 1:56 ` dhazeghi at yahoo dot com
2003-09-08 23:01 ` dbaron at dbaron dot org
2003-11-27 7:32 ` pinskia at gcc dot gnu dot org
2004-03-03 7:10 ` pinskia at gcc dot gnu dot org
2004-05-26 22:37 ` [Bug rtl-optimization/11680] " pinskia at gcc dot gnu dot org
2004-06-03 4:42 ` pinskia 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).