Please note that the content of this book primarily consists of articles
available from Wikipedia or other free sources online. In computer
programming, loop-invariant code consists of statements or expressions
(in an 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 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.