Optimizing sequential memory access in loops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have noticed that in examples like these:

void test1(int N, double *a)
{
  int i;
  for (i=0; i<N-1; i++)
    a[i] += a[i+1];
}
void test2(int N, double *a)
{
  int i;
  for (i=0; i<N-1; i++)
    a[i+1] += a[i];
}

GCC generates two memory loads per iteration (I checked svn HEAD on ia64 and 4.0.3 on i386). If loop unrolling is enabled, GCC is able to eliminate unneeded stores in second function, but not in first.

Should GCC be able to eliminate extraneous loads, given its current analysis/optimization abilities (i.e. is it a bug, or such analysis is not implemented yet)? If not, how would you estimate the difficulty of implementing an analysis pass that would improve such cases, and how useful it would be (how "real-world" applications would benefit from it)?

Thanks in advance.

Alexander Monakov


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux