8.5 Loop Rerolling

Many codes have loops that were unrolled manually over several iterations to amortize the cost of the branch at the bottom of the DO, for example:

DO 10 I = 1,N,3
X (I) = A (I) + B (I)
X (I+1) = A (I+1) + B (I+1)
X (I+2) = A (I+2) + B (I+2)
10    CONTINUE

KAP recognizes this example as an unrolled loop and rerolls it before looking for optimization opportunities as follows:

DO 2 I=1,(N+2)/3*3
X (I) = A (I) + B (I)
2 CONTINUE

Unrolled summations are also recognized, for example:

DO 10 I = 1,N,5
10 S = S + A(I) + A(I+1) + A(I+2) + A(I+3) + A(I+4)

Becomes:

DO 2 I=1,(N+4)/5*5
S = S + A(I)
2 CONTINUE


Previous Page | Next Page | Contents | Index |
Command-Line Qualifiers