This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Optimizing sequential memory access in loops
- From: "Alexander Monakov" <monoid at ispras dot ru>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 22 Mar 2007 21:19:26 +0300
- Subject: Optimizing sequential memory access in loops
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