You copied the Doc URL to your clipboard.

Conditional statements and efficient vectorization

For efficient vectorization, loops must contain mostly assignment statements and must limit the use of if and switch statements.

Loop invariant conditions are simple conditions that do not change between iterations of the loop. The compiler can move loop invariant conditions before the loop so that they are executed once, rather than on each loop iteration.

The compiler can vectorize more complex conditional operations by computing all pathways in vector mode and merging the results. If there is significant conditional computation, then performance might suffer.

The following example uses conditional statements in a way that is acceptable for vectorization.

float a[99], b[99], c[99];
int i, n;
for (i = 0; i < n; i++)
    if (c[i] > 0) a[i] = b[i] - 5.0f;
    else a[i] = b[i] * 2.0;