This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: loop optimizations
- From: Jan Hubicka <jh at suse dot cz>
- To: Marko Mlinar <markom at opencores dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: Sat, 26 Jan 2002 00:31:09 +0100
- Subject: Re: loop optimizations
- References: <017201c1a577$4aa800a0$4901010a@tyr>
> Hello !
>
> I have a short question:
> Is gcc 3.1 capable of convesion classical loops with simple iterators, e.g.
>
> int a[50], b[50], i;
> for (i = 0; i < 50; i++)
> {
> a[i] = b[i];
> }
>
> to more optimized code that uses test like instructions:
> i = 49;
> while (i != 0) /* Test instruction used */
> {
> a[i] = b[i];
> i--;
> }
Not exactly. Gcc is able to do loop reversal that would do the trick you
suggest, but only when the induction variable (i) is used only as the iteration
counter, not for something else. (or gcc figures out way how to replace that
uses by different construct, such as autoincrement addressing).
To do similar transformations as one you suggest in general, gcc need to do
more smart analysis and framework for that is being worked on, but it is not
ready for 3.1 (and it is not clear whether it will be in 3.2)
It is also important to point out that this particular transformation is hardly
win on modern CPUs, as the memory troughput is bottleneck, not the CPU power to
compute one extra operation and accessing memory block in reverse order is
often slower due to bypassing hardware prefetching.
Honza
>
> thanks,
> Marko
>