Loop splitting

From Free net encyclopedia

(Redirected from Loop peeling)

Loop splitting (or loop peeling) is a compiler optimization technique. It attempts to simplify a loop or eliminate dependencies by breaking it into multiple loops which have the same bodies but iterate over different contiguous portions of the index range.

A useful special case is loop peeling, which can simplify a loop with a problematic first (or first few) iteration by performing that iteration separately before entering the loop.

Here is an example of loop peeling. Suppose the original code looks like this:

for i from 1 to 100 do
  x[i] = x[1] + y[i];
od;

Since the assignment to the array x depends on the array x itself, the compiler cannot safely use parallelization in this loop. However if we omit the first iteration, thereby removing the problematic self reference to x[1] this problem is solved. We get the following after loop peeling:

x[1] = x[1] + y[1]
for i from 2 to 100 do
  x[i] = x[1] + y[i];
od;

Loop peeling was introduced in gcc in version 3.4.

Further reading

Template:Cite book

See also