Compilers
What is the main effect of loop unrolling?
- AFewer counter checks and branches, and easier reordering
- BThe loop body is reduced to one copy, making the program's code smaller
- CThe loop is extracted into a function that can be called from elsewhere
Show answer and explanation
Answer: A. Fewer counter checks and branches, and easier reordering
Loop unrolling writes, say, four copies of the loop body and runs a quarter as many iterations. Counter checks and branches shrink, and instructions from the copies can be interleaved, making it easier to hide operation latencies. Code grows in exchange and can strain the instruction cache. A single copy with smaller code is the reverse, and extracting a loop into a function is a different transformation.
- A. Correct. Branch overhead drops and instructions become easier to reorder.
- B. Multiple copies of the body make code larger, not smaller.
- C. Extracting into a function is a different transformation.