Code motion

It can be difficult to differentiate between different types of code motion, due to the inconsistent meaning of the terms surrounding it.

Compilers will interleave dependencies in a manner that maximizes the amount of instructions a CPU can process at any point in time.

Itanium relies on additional code scheduling from the CPU to maximize efficiency in the processor.

LLVM 15.0 will not sink an operation if any of its code paths include a store instruction, or if it may throw an error.

[8] GCC will move any code upwards or downwards if it "[does not] invalidate any existing dependences nor introduce new ones".

A diagram depicting an optimizing compiler removing a potentially useless call to assembly instruction "b" by sinking it to its point of use.
A diagram that demonstrates optimizing for size using code factoring, assuming all operations are not dependent on other operations executing before it.
An example of how a compiler might prevent dependency stalls in assembled code with code movement, by observing a dependency graph . Due to Out-of-order execution advancements, optimization may not have any benefit on modern CPUs.
A diagram depicting loop-invariant code motion over an execution graph. This assumes that D is invariant between loop executions.