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;
};
Non-ConfidentialPDF file icon PDF versionARM DUI0472M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.