Loop splitting



         


Loop splitting is a compiler optimization. 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 parallization 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;

The optimization loop peeling was introduced to gcc in version 3.4.





  View Live Article   This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License