Questions: Array Subscript Optimization

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A compiler applies strength reduction to the loop `for (i=0; i<n; i++) a[i] = 0;`. Which transformation best describes what happens to the address calculation `base + i * element_size`?

AThe multiplication is replaced by a left shift, because element_size is always a power of two
BA pointer `p` is initialized to `base` before the loop and incremented by `element_size` each iteration, replacing the multiply-add with a single add
CThe loop is unrolled so the multiplication only executes every other iteration
DThe subscript is cached and reused, so the multiplication executes once regardless of loop length
Question 2 Multiple Choice

A student claims that array subscript optimization changes which memory locations are accessed in order to improve performance. Is this correct?

AYes — the optimizer reorders memory accesses to improve cache behavior
BYes — the optimizer skips redundant accesses identified by data dependence analysis
CNo — strength reduction produces the same address sequence using cheaper arithmetic operations
DNo — the optimizer replaces array accesses with register variables, eliminating memory access entirely
Question 3 True / False

Strength reduction can be applied to `a[b[i]]` when `b[i]` is known to be monotonically increasing.

TTrue
FFalse
Question 4 True / False

In a doubly-nested loop accessing `a[i][j]`, strength reduction can eliminate both the outer and inner multiplications by maintaining a separate pointer for each loop level.

TTrue
FFalse
Question 5 Short Answer

Why is array subscript optimization especially important for dense linear algebra code rather than for code with irregular access patterns?

Think about your answer, then reveal below.