This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Loop unrolling
- To: egcs at cygnus dot com
- Subject: Re: Loop unrolling
- From: Sol Foster <colomon at ralf dot org>
- Date: Tue, 02 Jun 1998 10:38:22 -0400
Jeffrey A Law <law@cygnus.com> wrote:
> If you can provide source examples which show C++ & Java creating empty
> loops behind the programmer's back it would go a long way to convincing
> everyone that eliminating empty loops is a good idea.
The obvious example would be something like
class A
{
public: A () {}
};
....
new A [100];
In theory, the compiler should generate a loop to call the default
constructor for each element. The default constructor doesn't do
anything, though, so this loop would ideally go away. (Perhaps EGCS
already does this as a special case... I don't have the compiler handy to
test it.)
I'd argue that even more important would be case where the programmer
intentionally created an empty loop, something like this (quickly hacked
together, not actual tested code):
template <class iter> void
DisplayData (iter begin, iter end)
{
for (iter i = begin; i != end; i++)
i->Prepare ();
for (iter i = begin; i != end; i++)
i->Display ();
}
In many cases (perhaps even the normal case) the Prepare code might just
be an inlined empty function, in which case you'd like the first loop to
go away.
--
Sol Foster: colomon@ralf.org
Socks aren't vegatables -- they deserve to be wiped out.
-Neil