The benefits of loop unrolling are as follows:
Unrolling eliminates branches and some of the code.
Unrolling enables you to aggressively schedule (or pipeline) the loop to hide latencies if you have enough free registers to keep variables live.
The Pentium® 4 and Intel® Xeon™ processors can correctly predict the exit branch for an inner loop that has 16 or fewer iterations, if that number of iterations is predictable and there are no conditional branches in the loop. Therefore, if the loop body size is not excessive, and the probable number of iterations is known, unroll inner loops for:
Pentium 4 processors, until they have a maximum of 16 iterations
Pentium III or Pentium II processors, until they have a maximum of 4 iterations
A potential limitation is that excessive unrolling, or unrolling of very large loops, can lead to increased code size. For more information on how to optimize with the -unroll[n] (Linux*) or /Qunroll[n] (Windows*) option, refer to the Intel® Pentium® 4 and Intel® Xeon™ Processor Optimization Reference Manual.
The -unroll[n] (Linux*) or /Qunroll[n] (Windows*) option controls how the Intel® compiler handles loop unrolling. The following table summarizes how to use this option:
Windows |
Linux |
Description |
---|---|---|
/Qunrolln Synonym: |
-unrolln |
Specifies the maximum number of times you want to unroll a loop. The following examples unrolls a loop at most four times: ifort -unroll4 a.f (Linux) ifort /Qunroll4 a.f (Windows) Note The Itanium® compiler currently recognizes only n = 0; any other value is ignored. |
/Qunroll |
-unroll |
Omitting a value for n lets the compiler decide whether to perform unrolling or not. This is the default; the compiler uses default heuristics or defines n. |
/Qunroll0 |
-unroll0 |
Disables the loop unroller. To disable loop unrolling, specify n as 0. The following examples disables loop unrolling: ifort -unroll0 a.f (Linux) ifort /Qunroll0 a.f (Windows) |
For more information about the option behaviors listed above, see the following topic:
-unroll compiler option