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,bint 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].
Are compilers able to detect alternating accesses to arrays and interleave them in memory?
compilers;arrays;program optimization;memory management
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.  