Compilers

If a loop with 100 iterations is unrolled by replicating its body four times, how many counter checks and branches remain? (Assume 100 is divisible by 4.)

  1. A100
  2. B25
  3. C400
Show answer and explanation

Answer: B. 25

With four copies of the body, each iteration does the work of four original iterations, so there are 100 ÷ 4 = 25 iterations and only 25 counter checks and branches, a quarter of the original overhead. When the count is not divisible by 4, a short loop is appended to handle the remainder. 100 is the count without unrolling, and 400 mistakenly multiplies.

  • A. 100 is the count without unrolling.
  • B. Correct. 100 ÷ 4 = 25.
  • C. 400 is a mistaken multiplication.
Practice this topic Back to topic

More Compilers questions

  1. What is the usual sequence for producing an executable from a C program?
  2. What is the optimization called that examines short sequences of generated machine code through a small window and replaces wasteful instruction combinations with better ones?
  3. In the code above, which optimization applies after inlining sq, and with what result?
  4. Which describes software pipelining?
  5. Why does a compiler with strict settings not reorder the floating-point sum (a + b) + c into a + (b + c) on its own?