3.23 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 may 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;
Related concepts
3.6 Automatic vectorization
3.17 Nonvectorization on conditional loop exits
Related reference
8.189 --vectorize, --no_vectorize
3.11 Recommended loop structure for vectorization
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.