-Cu: Loop Unrolling

Group

OPTIMIZATIONS

Scope

Function

Syntax
-Cu[=i<number>] 
Arguments

<number>: number of iterations for unrolling, between 0 and 1024

Default

None

Defines

None

Pragmas

#pragma LOOP_UNROLL: Force Loop Unrolling

#pragma NO_LOOP_UNROLL: Disable Loop Unrolling

Description

Enables loop unrolling with the following restrictions:

Examples
Listing: for Loop


-Cu int i, j; 
j = 0; 
for (i=0; i<3; i++) { 
  j += i; 
} 

When the -Cu compiler option is used, the Compiler issues an information message Unrolling loop and transforms this loop as shown in the following listing:

Listing: Transformation of the for Loop


j += 1; j += 2; 
i  = 3; 

The Compiler also transforms some special loops, i.e., loops with a constant condition or loops with only one pass:

Listing: Example for a loop with a constant condition


for (i=1; i>3; i++) {   j += i; 
} 

The Compiler issues an information message Constant condition found, removing loop and transforms the loop into a simple assignment, because the loop body is never executed:

i=1; 
Listing: Example for a loop with only one pass


for (i=1; i<2; i++) {   j += i; 
} 

The Compiler issues a warning 'Unrolling loop' and transforms the for loop into

j += 1;
i  = 2;

because the loop body is executed only once.