Loop interchange
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)