Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Loop splitting
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Loop peeling== Loop peeling is a special case of loop splitting which splits any problematic first (or last) few iterations from the loop and performs them outside of the loop body. Suppose a loop was written like this: <syntaxhighlight lang="c"> int p = 10; for (int i=0; i<10; ++i) { y[i] = x[i] + x[p]; p = i; } </syntaxhighlight> Notice that <code>p = 10</code> only for the first iteration, and for all other iterations, <code>p = i - 1</code>. A compiler can take advantage of this by [[loop unwinding|unwinding]] (or "peeling") the first iteration from the loop. After peeling the first iteration, the code would look like this: <syntaxhighlight lang="c"> y[0] = x[0] + x[10]; for (int i=1; i<10; ++i) { y[i] = x[i] + x[i-1]; } </syntaxhighlight> This equivalent form eliminates the need for the variable <code>p</code> inside the loop body. Loop peeling was introduced in [[GNU Compiler Collection|gcc]] in version 3.4. More generalised loop splitting was added in GCC 7.<ref name="R1"/>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)