Code scheduling is a form of program optimization that reorders operations in machine code while satisfying three main types of constraints: data dependence constraints to preserve program semantics, resource constraints to avoid oversubscribing machine resources, and true/anti dependencies related to reads and writes of the same memory location. Data dependence analysis is needed but is generally undecidable at compile time so the compiler must conservatively assume operations may refer to the same location. Register allocation and code scheduling affect each other, so scheduling is often done before or after allocation to minimize storage dependences. Scheduling within basic blocks is relatively easy but blocks tend to be small with little parallelism. Memory loads in particular can benefit from speculative execution.