Compilers

What happens to generated code when register allocation causes a "spill"?

  1. AStores and reloads to the stack are added, tending to slow the code
  2. BThe number of registers grows automatically so every value fits in a register
  3. CUnused values are deleted, reducing the number of instructions
Show answer and explanation

Answer: A. Stores and reloads to the stack are added, tending to slow the code

A spill places some values in memory (the stack) when more values are live than there are registers. Each use of such a value needs a load and each update a store, adding instructions and memory-access delays. Compilers therefore keep heavily used values, such as those in loops, in registers and choose rarely used values to spill. The register count is fixed by the CPU and does not grow, and deleting unused values is a separate matter.

  • A. Correct. Extra stores and reloads tend to slow the code.
  • B. The register count is fixed by the CPU.
  • C. Deleting unused values is a different optimization.
Practice this topic Back to topic

More Compilers questions

  1. What is the main purpose of instruction scheduling in a compiler?
  2. What is the effect of applying tail-call optimization to the final recursive call in the function above?
  3. Which correctly distinguishes a compiler from an interpreter?
  4. Which describes a runtime that uses JIT compilation?
  5. Which describes the basic structure of LLVM?