UNROLL | NOUNROLL

Category

Optimization and tuning

Pragma equivalent

#pragma unroll

Purpose

Controls loop unrolling, for improved performance.

Syntax

Read syntax diagramSkip visual syntax diagramUNROLLAUTOYESNOnNOUNROLL

Defaults

UNROLL(AUTO)

Parameters

YES
Allows the compiler to unroll loops that are annotated (for example, using a pragma), unless it is overridden by #pragma nounroll.
NO
Means that the compiler is not permitted to unroll loops in the compilation unit, unless unroll or unroll(n) pragmas are specified for particular loops.
AUTO
This option is the default. It enables the compiler to unroll loops that are annotated (for example, using a pragma) and loops which the compiler has decided (via heuristics) are appropriate for unrolling. AUTO should only be specified if you have specified OPTIMIZE(2) or greater and COMPACT is not specified.
n

Instructs the compiler to unroll loops by a factor of n. In other words, the body of a loop is replicated to create n copies, and the number of iterations is reduced by a factor of 1/n. The UNROLL(n) option specifies a global unroll factor that affects all loops that do not have an unroll pragma already. The value of n must be a positive integer.

Specifying #pragma unroll(1) or UNROLL(1) option disables loop unrolling, and is equivalent to specifying #pragma nounroll or UNROLL option.

Usage

The UNROLL compiler option instructs the compiler to perform loop unrolling, which is an optimization that replicates a loop body multiple times, and adjusts the loop control code accordingly. Loop unrolling exposes instruction level parallelism for instruction scheduling and software pipelining and thus can improve a program's performance. It also increases code size in the new loop body, which may increase pressure on register allocation, cause register spilling, and therefore cause a loss in performance. Before applying unrolling to a loop, you must evaluate these tradeoffs. In order to check if the unroll option improves performance of a particular application, you should compile your program with the usual options, run it with a representative workload, recompile it with the UNROLL option and/or unroll pragmas, and rerun it under the same conditions to see if the UNROLL option leads to a performance improvement.

Specifying UNROLL without any suboptions is equivalent to specifying UNROLL(YES).

Specifying NOUNROLL is equivalent to specifying UNROLL(NO).

The usage status of this option is inserted in the object file to aid you in diagnosing a problem with your program.

Predefined macros

None.