Loop unrolling involves replicating the body of the loop to reduce the required number of tests if the number of iterations are constant. For example consider the following loop:
I = 1 while ( I <= 100) { x [ I ] = 0; I ++; }
In this case, the test I <= 100 will be performed 100 times. But if the body of the loop is replicated, then the number of times this test will need to be performed will be 50. After replication of the body, the loop will be:
I = 1 while( I <= 100) { x [ I ] = 0; I ++; X [ I ] = 0; I ++; }
It is possible to choose any divisor for the number of times the loop is executed, and the body will be replicated that many times. Unrolling once ”that is, replicating the body to form two copies of the body ”saves 50% of the maximum possible executions.