This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Loop unrolling
- To: Joern Rennecke <amylaar at cygnus dot co dot uk>
- Subject: Re: Loop unrolling
- From: Gavin Romig-Koch <gavin at cygnus dot com>
- Date: Tue, 2 Jun 1998 15:58:10 -0400 (EDT)
- Cc: knobi at rocketmail dot com (Martin Knoblauch), leei at ai dot sri dot com, steve at icarus dot icarus dot com, pfeifer at dbai dot tuwien dot ac dot at, egcs at cygnus dot com
- References: <19980602093834.24519.rocketmail@web2.rocketmail.com><199806021614.RAA14728@phal.cygnus.co.uk>
Joern Rennecke writes:
> > > But the correct way to write an empty loop that
> > shouldn't be deleted
> > > (a timing loop) already exists:
> > >
> > > {
> > > volatile int i;
> > > for (i = 0; i < 10000; ++i);
> > > }
> > >
> >
> > Hmm. Does this prevent the loop from being deleted,
> > or would it allow the compiler to just assign
> > 9999 to "i"?
>
> AFAIK it prevents current versions of gcc to delete the loop (unless the loop
> is unreachable), but the standard's 'as if' rule still allows to optimize
> the loop away.
No. The "volatile" requires the compiler to keep the implied
loads and stores, dispite the as-if rule, and thus the loop is
not empty, and thus not deleted.
-gavin...