Empty loops

Nathan Sidwell nathan@codesourcery.com
Wed Nov 24 14:47:00 GMT 2004


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



More information about the Gcc-help mailing list