Questions: Dead Code Elimination

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A compiler sees: `x = a * b + c` on line 5. Variable x is overwritten on line 12 without being read between lines 5 and 12. Variables a, b, and c are each used only in this expression. What does dead code elimination do?

AIt removes only line 5, since x is dead after that assignment, but a, b, and c remain because they were 'used' on line 5
BIt removes line 5 and also removes any assignments that produced a, b, and c, since those values are now also dead
CIt cannot remove line 5 because a, b, and c might have side effects from their definitions
DIt marks line 5 as unreachable code and uses control flow analysis to eliminate it
Question 2 Multiple Choice

What is the fundamental difference between dead assignment elimination and unreachable code elimination?

ADead assignment elimination is safe; unreachable code elimination might change program behavior
BDead assignment elimination relies on live variable analysis to identify values that are computed but never read; unreachable code elimination relies on control flow analysis to find basic blocks with no reachable predecessors
CDead assignment elimination only works on scalars; unreachable code elimination works on any code block
DUnreachable code elimination is a subset of dead assignment elimination — all unreachable code contains dead assignments
Question 3 True / False

Dead code elimination can reveal additional dead code, because removing a dead assignment may make the computations that produced the assigned value dead as well.

TTrue
FFalse
Question 4 True / False

If a code block is seldom executed during any test run, a compiler can determine it is unreachable and safely eliminate it.

TTrue
FFalse
Question 5 Short Answer

What makes 'aggressive' dead code elimination different from the naive approach, and why is it particularly effective after function inlining?

Think about your answer, then reveal below.