Content deleted Content added
m →Example: typo |
Reaching definitions analysis can be used for this |
||
Line 1:
{{Unreferenced|date=May 2007}}
In [[computer programming]], '''loop-invariant code''' consists of statements or expressions (in an [[imperative programming|imperative]] [[programming language]]) which can be moved outside the body of a loop without affecting the semantics of the program.
'''Loop-invariant code motion''' (also called '''hoisting''' or '''scalar promotion''') is a [[compiler optimization]] which performs this movement automatically. Usually a [[Reaching definition|reaching definitions analysis]] is used to detect whether a statement or expression is loop invariant. For example, if all reaching definitions for the operands of some simple expression are outside of the loop, the expression can be moved out of the loop.
Loop-invariant code which has been hoisted out of a loop is executed less often, providing a speedup. Another effect of this transformation is allowing constants to be stored in registers and not having to calculate the address and access the memory (or cache line) at each iteration.
|