The -unroll[n] option is used in the following way:
-unrolln specifies the maximum number of times you want to unroll a loop. The following example unrolls a loop at most four times:
ifort -unroll4 a.f
To disable loop unrolling, specify n as 0. The following example disables loop unrolling:
ifort -unroll0 a.f
-unroll (n omitted) lets the compiler decide whether to perform unrolling or not.
-unroll0 (n = 0) disables unroller.
Itanium® compiler currently uses only n = 0; any other value is NOP.
The benefits are:
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 Intel®
Pentium®
4 or Intel®
Xeon(TM) 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 or Intel Xeon processor, until they have a maximum of 16
iterations
- Pentium III or Pentium
II processors, until they have a maximum of 4 iterations
The potential costs are:
Excessive unrolling, or unrolling of very large loops can lead to increased code size.
If the number of iterations of the unrolled loop is 16 or less, the branch predictor should be able to correctly predict branches in the loop body that alternate direction.
For more information on how to optimize with -unroll[n], refer to Intel® Pentium® 4 and Intel® Xeon(TM) Processor Optimization Reference Manual.