This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[doc] empty loops
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 24 Nov 2004 14:48:38 +0000
- Subject: [doc] empty loops
- Organization: Codesourcery LLC
this patch clarifies why empty loops might be removed. It comes
from answering http://gcc.gnu.org/ml/gcc-help/2004-11/msg00169.html
ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-11-24 Nathan Sidwell <nathan@codesourcery.com>
* trouble.texi (Non-bugs): Clarify empty loop removal.
Index: doc/trouble.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/trouble.texi,v
retrieving revision 1.29
diff -c -3 -p -r1.29 trouble.texi
*** doc/trouble.texi 5 Nov 2004 01:36:57 -0000 1.29
--- doc/trouble.texi 24 Nov 2004 14:45:33 -0000
*************** to have a delay, so deleting them will n
*** 1217,1229 ****
faster.
However, the rationale here is that optimization of a nonempty loop
! cannot produce an empty one, which holds for C but is not always the
! case for C++.
! @opindex funroll-loops
! Moreover, with @option{-funroll-loops} small ``empty'' loops are already
! removed, so the current behavior is both sub-optimal and inconsistent
! and will change in the future.
@item
Making side effects happen in the same order as in some other compiler.
--- 1217,1244 ----
faster.
However, the rationale here is that optimization of a nonempty loop
! cannot produce an empty one. This held for carefully written C compiled
! with less powerful optimizers but is not always the case for carefully
! written C++ or with more powerful optimizers.
!
! 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.
@item
Making side effects happen in the same order as in some other compiler.