This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
missing optimization - don't compute return value not used?
- From: Neal Becker <ndbecker2 at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 26 Sep 2007 08:51:07 -0400
- Subject: missing optimization - don't compute return value not used?
gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)
I noticed the following code
=== version 1:
template<typename a_t, typename b_t>
inline a_t append (a_t & a, b_t const& b) {
a.insert (a.end(), b.begin(), b.end());
return a;
}
=== version 2:
template<typename a_t, typename b_t>
inline void append (a_t & a, b_t const& b) {
a.insert (a.end(), b.begin(), b.end());
}
When instantiated for a_t, b_t std::list<T>. When called by code that _did
not use the return value_, I had assumed that since the returned value is
not used, the 2 versions would be equivalent. Instead, (compiling
with -O3), version 2 runs very fast, but version 1 is extremely slow. Is
it really necessary to construct the returned value even when it is seen
that it is not used?