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] |
Hi! While designing an iterator for iterating a 3d grid for numerical physics, I stumbled over the problem, that gcc fully instantiates a temporary for an operator like [full compilable example attached, compile with g++ -S -O3 and see the difference in output for both methods] Iterator operator+(int i) const { Iterator it(*this); it.m_i += i; return it; } even if only the (updated) m_i field of the new instance is used (read once) in uses like array(i+1); which is optimized ok if written as (ugly) array(i,+1) and defining double& operator(const Iterator& i, int d) { return a[i.m_i+d]; } which the compiler should be able to guess. Is there a way to make the compiler optimize away this local temporary class instance? Please CC me, I'm not on the list. Richard. -- Richard Guenther <richard.guenther@uni-tuebingen.de> WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/ The GLAME Project: http://www.glame.de/
Attachment:
iterator.cpp
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |