-funroll-loops (-qunroll), -funroll-all-loops (-qunroll=yes)
Category
Pragma equivalent
#pragma unroll
Purpose
Controls loop unrolling, for improved performance.
- -funroll-loops
- Instructs the compiler to perform basic loop unrolling.
- -funroll-all-loops
- Instructs the compiler to search for more opportunities for loop unrolling than that performed with -funroll-loops. In general, -funroll-all-loops has more chances to increase compile time or program size than -funroll-loops processing, but it might also improve your application's performance.
When -funroll-loops or -funroll-all-loops is in effect, the optimizer determines and applies the best unrolling factor for each loop; in some cases, the loop control might be modified to avoid unnecessary branching. The compiler remains the final arbiter of whether the loop is unrolled.
Syntax
Option syntax .- -funroll-loops-----. >>-+- -funroll-all-loops-+-------------------------------------><
Option syntax .-auto-. .-unroll--=--+-yes--+-. | +-no---+ | | '-n----' | >>- -q--+-nounroll------------+--------------------------------><
Defaults
-funroll-loops or -qunroll=auto
Parameters
The following suboptions are for -qunroll only:
- auto
- This suboption is equivalent to -funroll-loops.
- yes
- This suboption is equivalent to -funroll-all-loops.
- no
- Instructs the compiler to not unroll loops.
- 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 -qunroll=n option specifies a global unroll factor that affects all loops that do not already have an unroll pragma. The value of n must be a positive integer.
- Specifying #pragma unroll(1) or -qunroll=1 disables loop unrolling, and is equivalent to specifying #pragma nounroll or -qnounroll. If n is not specified and if -qhot, -O4, or -O5 is specified, the optimizer determines an appropriate unrolling factor for each nested loop.
- The compiler might limit unrolling to a number smaller than the value you specify for n. This is because the option form affects all loops in source files to which it applies and large unrolling factors might significantly increase compile time without necessarily improving runtime performance. To specify an unrolling factor for particular loops, use the #pragma form in those loops.
Specifying -qunroll without any suboptions is equivalent to -qunroll=yes.
Usage
The pragma overrides the option setting for a designated loop. However, even if #pragma unroll is specified for a given loop, the compiler remains the final arbiter of whether the loop is unrolled.
Only one pragma can be specified on a loop.
The pragma affects only the loop that follows it. An inner nested loop requires a #pragma unroll directive to precede it if the wanted loop unrolling strategy is different from that of the prevailing option.
Predefined macros
None.