3.13 Carry-around scalar variables and vectorization

Scalar variables that are used and then set in a loop can cause problems for vectorization.

A scalar variable that is used but not set in a loop is replicated in each position in a vector register and the replication is used in the vector calculation.

A scalar that is set and then used in a loop is promoted to a vector. These variables generally hold temporary scalar values in a loop that now has to hold temporary vector values. In the following example, x is a used scalar and y is a promoted scalar.

Vectorizable loop:

float a[99], b[99], x, y;
int i, n;
for (i = 0; i < n; i++)
    y = x + b[i];
    a[i] = y + 1/y;

A scalar that is used and then set in a loop is called a carry-around scalar. These variables are a problem for vectorization because the value computed in one pass of the loop is carried forward into the next pass. In the following example, x is a carry-around scalar.

Nonvectorizable loop

float a[99], b[99], x;
int i, n;
for (i = 0; i < n; i++)
    a[i] = x + b[i];
    x = a[i] + 1/x;
Related concepts
3.17 Nonvectorization on conditional loop exits
3.16 Nonvectorization on loops containing pointers and indirect addressing
3.15 Vectorization on loops containing pointers
3.14 Reduction of a vector to a scalar
3.12 Data dependency conflicts when vectorizing code
3.9 Factors affecting NEON vectorization performance
3.6 Automatic vectorization
Related reference
3.11 Recommended loop structure for vectorization
8.189 --vectorize, --no_vectorize
3.10 NEON vectorization performance goals
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.