This is the mail archive of the gcc-patches@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]

Re: [doc] empty loops


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


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