Loops can be formed with the usualLoops must have a single entry and a single exit to be vectorized. The following examples illustrate loop constructs that can and cannot be vectorized.
Example: Vectorizable structure
The following example shows a loop that cannot be vectorized because of the inherent potential for an early exit from the loop.
Example: Non-vectorizable structure
Loop Exit Conditions
Loop exit conditions determine the number of iterations a loop executes. For example, fixed indexes for loops determine the iterations. The loop iterations must be countable; in other words, the number of iterations must be expressed as one of the following:
- A constant.
- A loop invariant term.
- A linear function of outermost loop indices.
In the case where a loops exit depends on computation, the loops are not countable. The examples below show loop constructs that are countable and non-countable.
Example: Countable Loop