HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Are compilers able to detect alternating accesses to arrays and interleave them in memory?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
arraysaccessescompilersareinterleavedetectmemoryandthemalternating

Problem

Is it possible to design a compiler which optimizes a loop in which arrays are accessed in alternate fashion? For example like this:

// int[] a,b
int sum = 0;
for(int i = 0; i < n; i++)
{
  sum += a[i] + b[i];
}


With the usual sequential array storage, a[i] and b[i] may be far away from each other in memory. Therefore, I think a good compiler optimization would detect that a[i] and b[i] are always accesses at the "same" time, and store the arrays interleaved, that is a[0] b[0] a[1] b[1] ... so that one memory access may retrieve both a[i] and b[i].

Solution

Some work has been done that matches your description. For instance:

  • Compiler-directed array interleaving for reducing energy in multi-bank memories. by Delaluz, V. Design Automation Conference, 2002. Proceedings of ASP-DAC 2002. 7th Asia and South Pacific and the 15th International Conference on VLSI Design. Proceedings.



describes a such an optimization.

Context

StackExchange Computer Science Q#3433, answer score: 11

Revisions (0)

No revisions yet.