Loop Fission
Loop fission, also known as loop distribution, is an optimization technique that splits a single loop into multiple loops over the same iteration range, with each handling a subset of the original loop’s operations. This transformation improves data locality, enhances cache efficiency, and enables better parallelization by reducing dependencies within a loop body. By breaking down complex loops, loop fission can optimize memory access patterns and improve overall program performance while preserving the original computation logic.
Loop Fission Transformation in emmtrix Studio
emmtrix Studio implements loop fission using #pragma directives or via the GUI. Loop fission is a transformation that breaks a loop into multiple loops over the same index range with each taking only a part of the original loop’s body.
Typical Usage and Benefits
Loop fission is used to achieve better utilization of locality of reference by breaking down a large loop body into smaller ones.
Example
/* The following code tests loop fission transformation applied to a for loop: */
int main() {
int i, j;
int a[10], b, c, d;
#pragma EMX_TRANSFORMATION LoopFission
for (i = 0; i < 10; i++) {
d = 0;
a[i] = i * i;
c = 9;
b = i;
b = 8 + i * b;
if (a[i] > 50) {
c = c + a[i];
printf(”Inside
if, a[ % d] = % d and c = % d\ n”, i, a[i], c);
} else {
printf(”Inside
else, c = % d\ n”, c);
printf(”Inside
else, a[ % d] = % d\ n”, i, a[i]);
}
}
}
|
/* The generated code has multiple loops, each loop containing groups of statements from the old loop
that have dependencies on one another: */
int main() {
int i;
int j;
int a[10];
int b;
int c;
int d;
{
for (i = 0; i < 10; i = i + 1) {
d = 0;
}
for (i = 0; i < 10; i = i + 1) {
a[i] = i * i;
c = 9;
if (a[i] > 50) {
c = c + a[i];
printf(”Inside
if, a[ % d] = % d and c = % d\ n”, i, a[i], c);
} else {
printf(”Inside
else, c = % d\ n”, c);
printf(”Inside
else, a[ % d] = % d\ n”, i, a[i]);
}
}
for (i = 0; i < 10; i = i + 1) {
b = i;
b = 8 + i * b;
}
}
}
|