This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Empty loops
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: jlh <jlh at gmx dot ch>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 24 Nov 2004 14:47:07 +0000
- Subject: Re: Empty loops
- Organization: Codesourcery LLC
- References: <41A49841.2080806@gmx.ch>
jlh wrote:
docs> ...so deleting them will not make real programs run any faster.
docs> However, the rationale here is that optimization of a nonempty
docs> loop cannot produce an empty one, which holds for C but is not
docs> always the case for C++.
This is the part I don't get. Why can the optimization of a C loop
never yield an empty loop? Take this trivial example:
Of course no-one would write this, but it's an example where an
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
you've answered your own question. The writer of the docs meant to
say 'holds for C written by someone who is careful and compiled
by __DATE__ era compilers'. Unfortunately
1) programmers' concentration can slip
2) optimizers have become more powerful
For C++, the docs say that things are different. Here's another
example, that is somewhat more realistic. First we define a function
What's being hinted at is that the definition
A ary[50];
needs to emit code to construct the elements, that will be a loop. If
the ctor turns out to be a nop, the loop should evaporate.
The documentation needs revising, methinks
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk