Compilers

What is the main purpose of instruction scheduling in a compiler?

  1. AReducing the instruction count by any means, even if program results change
  2. BReordering without changing results to fill latencies
  3. CRearranging instructions into the order chosen by the OS scheduler
Show answer and explanation

Answer: B. Reordering without changing results to fill latencies

When a load or multiply result is not immediately available, placing its consumer right after it stalls the CPU. Instruction scheduling reorders instructions, respecting data dependences so results are unchanged, to insert independent instructions in between and make use of the waiting time. It is especially effective on in-order CPUs. Transformations that change results are not allowed, and the OS scheduler decides process switching, a separate mechanism.

  • A. Transformations that change results are not allowed.
  • B. Correct. It reorders within dependences to fill latencies.
  • C. The OS scheduler decides process switching, a separate mechanism.
Practice this topic Back to topic

More Compilers questions

  1. What is the effect of applying tail-call optimization to the final recursive call in the function above?
  2. Which correctly distinguishes a compiler from an interpreter?
  3. Which describes a runtime that uses JIT compilation?
  4. Which describes the basic structure of LLVM?
  5. When is the no-optimization setting of a compiler (such as -O0) commonly used?