A loop that has results from one iteration feeding back into a future iteration of the same loop is said to have a data dependency conflict. The conflicting values might be array elements or a scalar such as an accumulated sum.
Loops containing data dependency conflicts might not be completely optimized. Detecting data dependencies involving arrays or pointers requires extensive analysis of the arrays used in each loop nest. It also involves examination of the offset and stride of accesses to elements along each dimension of arrays that are both used and stored in a loop. If there is a possibility of the usage and storage of arrays overlapping on different iterations of a loop, then there is a data dependency problem. A loop cannot be safely vectorized if the vector order of operations can change the results. In these cases, the compiler detects the problem and leaves the loop in its original form or carries out a partial vectorization of the loop. This type of data dependency must be avoided in your code to achieve the best performance.
In the loop shown in Example 3, the reference to
the top of the loop conflicts with the store into
the bottom. Performing vectorization on this loop gives a result
that differs to the result that is obtained without vectorization,
so it is left in its original form.
Information from other array subscripts is used as part of
the analysis of dependencies. The loop in Example 4 vectorizes because the nonvector subscripts
of the references to array
a can never be equal.
They can never be equal because
n is not equal
n+1 and so gives no feedback between iterations.
The references to array
a use two different pieces
of the array, so they do not share data.