This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]