This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [doc] empty loops
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 24 Nov 2004 19:41:01 +0100
- Subject: Re: [doc] empty loops
- References: <41A49F46.4010805@codesourcery.com>
Hello,
> this patch clarifies why empty loops might be removed. It comes
> from answering http://gcc.gnu.org/ml/gcc-help/2004-11/msg00169.html
>
> ! Thus GCC will remove loops whenever it can determine no operations
> ! occurring within the loop are externally visible (apart from the time
> ! taken to execute them, of course). Be aware of this when performing
> ! timing tests, for instance the following loop can be completely removed,
> ! provided @code{some_expression} can provably not change any global state.
>
> ! @smallexample
> ! @{
> ! int sum = 0;
> ! int ix;
> !
> ! for (ix = 0; ix != 10000; ix++)
> ! sum += some_expression;
> ! @}
> ! @end smallexample
> !
> ! Even though @code{sum} is accumulated in the loop, no use is made of
> ! that summation, so the accumulation can be removed.
is this really true? The last time I checked we did not remove
provably finite empty loops (except for those that do not iterate too
much, that may get removed as a side effect of unrolling), although
patch for this is pending for some time.
Zdenek