Jump to content

Loop interchange

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fadmmatt (talk | contribs) at 02:04, 4 May 2005 (Added loop interchange.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In compiler theory, loop interchange is the process of exchanging the order of two iteration variables.

For example, in the code fragment:

for i from 0 to 10
 for j from 0 to 20
   a[i,j] = i + j

loop interchange would result in:

for j from 0 to 20
 for i from 0 to 10
   a[i,j] = i + j

On occasion, such a transformation may lead to opportunities to further optimize, such as vectorization of the array assignments.

Safety

It is not always safe to exchange the iteration variables due to dependencies between statements for the order in which they must execute. In order to determine whether a compiler can safely interchange loops, dependence analysis is required.

Further reading

. ISBN 1-55860-286-0. {{cite book}}: Missing or empty |title= (help); Unknown parameter |Author= ignored (|author= suggested) (help); Unknown parameter |Publisher= ignored (|publisher= suggested) (help); Unknown parameter |Title= ignored (|title= suggested) (help); Unknown parameter |Year= ignored (|year= suggested) (help)

See also

Loop splitting Loop skewing Loop fusion Loop unwinding