This recommendation is part of the open catalog of best practice rules for performance that is automatically detected and reported by Codee.
Issue
The loop contains independant blocks some of which can be vectorized if scalars are promoted to vectors.
Relevance
Many times loops contain independent computations some of which can be vectorized while others can not. By extracting the vectorizable computations to a new loop, it can become vectorized with the corresponding performance increase. This transformation is called loop fission.
However, in order to perform the loop fission, temporary scalar values in the loop need to be stored in a vector. After loop fission, we end up with two loops, and the second loop is depending on the data generated in the first loop. By promoting temporary scalar values to a vector, we preserve the values calculated by the first loop to be used in a second loop.
Actions
Promote the computation of the temporary scalar variable to a vector and perform the loop fission.
Code example
The following loop contains an indirect array access that may inhibit vectorization:
int expensive_computation(int *C, int i) { return C[i] * 2; }
void example(int *A, int *C) {
for (int i = 0; i < 1000; i++) {
int a = expensive_computation(C, i);
A[C[i]] = a;
}
}
The expensive computation can be separated from the indirect array access by introducing a new array holding the computation results and then splitting the loop. This way, the loop performing the expensive computations can be vectorized:
int expensive_computation(int *C, int i) { return C[i] * 2; }
void example(int *A, int *C) {
int a[1000];
for (int i = 0; i < 1000; i++) {
a[i] = expensive_computation(C, i);
}
for (int i = 0; i < 1000; i++) {
A[C[i]] = a[i];
}
}

Building performance into the code from day one with Codee