Questions: Vectorization and SIMD Code Generation

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A compiler refuses to vectorize the loop: `for (i=1; i<n; i++) A[i] = A[i-1] * 2;`. The most accurate explanation is:

AThe loop body is too complex for the SIMD vectorization pass to analyze
BThere is a loop-carried dependency: iteration i reads the value written by iteration i-1, so parallel execution would produce wrong results
CThe array is too small — vectorization is only beneficial for large arrays
DThe multiplication operation is not supported on this CPU's SIMD unit
Question 2 Multiple Choice

A loop processes 1,007 elements using AVX (256-bit registers, 8 floats per register). How does the compiler handle the elements that don't fit evenly into the SIMD width?

AIt rounds down to 1,000 elements and skips the last 7 to keep the loop simple
BIt pads the array allocation to 1,008 elements so the count is a multiple of 8
CIt generates a scalar remainder loop that processes the last 7 elements after 125 full vector iterations
DIt refuses to vectorize because the element count must be a compile-time constant divisible by 8
Question 3 True / False

Even when a loop has a loop-carried dependency (such as summing all elements of an array), a compiler may still be able to vectorize it by using multiple partial accumulators in separate vector lanes.

TTrue
FFalse
Question 4 True / False

When a compiler can seldom prove that two pointer arguments do not alias (point to overlapping memory), it will generally refuse to vectorize any loop involving those pointers.

TTrue
FFalse
Question 5 Short Answer

Why is proving absence of loop-carried dependencies the critical prerequisite for vectorization, and what can programmers do to help the compiler vectorize loops it would otherwise reject?

Think about your answer, then reveal below.