Questions: Constant Propagation and Folding

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In a control flow graph, one branch of an if-statement assigns x = 5 and the other assigns x = 7. At the merge point after both branches, what does constant propagation's lattice assign to x?

Ax = 5 (the first assignment wins)
Bx = 6 (the average of the two values)
Cx = 'not a constant' (multiple different values may reach this point)
Dx = 'undefined' (the assignment is considered ambiguous)
Question 2 Multiple Choice

After constant propagation and folding replace a variable with a known constant in a branch condition, what further optimization typically becomes possible?

ALoop unrolling, because the loop bound is now statically known
BDead code elimination, because the branch condition is now statically true or false
CRegister allocation, because constants do not need to occupy registers
DFunction inlining, because constant arguments can be substituted at call sites
Question 3 True / False

Constant folding and constant propagation are the same operation: both replace program values with known constants.

TTrue
FFalse
Question 4 True / False

If every reaching definition of a variable assigns the same constant value, the compiler can safely replace all uses of that variable with that constant.

TTrue
FFalse
Question 5 Short Answer

Why do constant propagation and constant folding typically create cascading opportunities for further compiler optimizations, rather than being a self-contained pass with limited effect?

Think about your answer, then reveal below.