Questions: Loop Unrolling

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A loop body contains four independent array reads followed by arithmetic on each. After unrolling by a factor of 4, what benefit does the compiler gain beyond simply reducing branch count?

AThe compiler can eliminate three of the four reads through common subexpression elimination
BThe larger basic block lets the compiler schedule multiple independent operations across functional units simultaneously, exploiting instruction-level parallelism
CThe loop will execute in exactly one-fourth the wall-clock time due to branch elimination alone
DRegister pressure is reduced because fewer variables are live at any point
Question 2 Multiple Choice

A compiler unrolls a loop of 998 iterations by a factor of 4. Besides the main unrolled loop body, what else must the compiler generate?

ANothing extra — the compiler rounds to 996 iterations and discards the remainder silently
BA remainder loop (epilogue) of 2 iterations to handle the 2 leftover elements that don't fit into groups of 4
CAn additional runtime branch inside the unrolled body to detect when the iteration count has been reached
DA prologue that aligns the loop to a multiple of 4 before entering the main unrolled body
Question 3 True / False

Loop unrolling can sometimes decrease performance despite reducing branch count, because duplicating the loop body increases code size and may cause instruction cache pressure.

TTrue
FFalse
Question 4 True / False

Loop unrolling typically improves performance for any loop, regardless of loop body size or trip count, because eliminating branches typically saves more time than it costs.

TTrue
FFalse
Question 5 Short Answer

Explain why loop unrolling can sometimes decrease performance rather than improve it, even though it reduces the number of branch instructions executed.

Think about your answer, then reveal below.