What kind of optimization moves computation out of a frequently executed loop?

Code motion is an optimization technique used in compilers where computations that produce the same result regardless of loop iterations are moved outside of a loop. This reduces the number of operations performed inside the loop, improving the efficiency of the code.

For example, if a computation inside a loop doesn’t depend on the loop’s index, it can be calculated once before the loop starts and then reused within the loop.