This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16405] Non optimized code when using default copy constructor
- From: "guillaume dot melquiond at ens-lyon dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jul 2004 09:19:43 -0000
- Subject: [Bug c++/16405] Non optimized code when using default copy constructor
- References: <20040707115615.16405.guillaume.melquiond@ens-lyon.fr>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From guillaume dot melquiond at ens-lyon dot fr 2004-07-19 09:19 -------
As a follow-up, I also tested with g++ 3.4.1 and 3.5-20040717.
The problem still exists with 3.4.1. There are still one more temporary and one
more copy than with 3.3.4.
The situation is a bit better with 3.5 than it was with the previous tested
snapshot. It is almost as good as with 3.4.1. There are only two more
temporaries and one more copy than with 3.3.4.
So both gcc 3.4 and 3.5 produce one more copy than gcc 3.3. I timed the cost of
this extra copy on the code below (-O3 compilation as before). It incurs a ~25%
slowdown of the whole program on an Intel P4 processor.
-------------------------------------------------------
struct T {
int a[500];
T &operator+=(T const &v) { for(int i = 0; i < 500; ++i) a[i] += v.a[i];
return *this; }
T operator+(T const &v) const { T t = *this; t += v; return t; }
};
T a, b, c;
int main() {
for(int i = 0; i < 10000000; ++i) a = b + c;
return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16405