This is the mail archive of the gcc@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: loop optimizations


> 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
> 


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