Back to the 2026 paper

Module 4: Intermediate Code Generation, Code Improvement (optimization)

20262m

Which optimization eliminates repeated computation of the same expression?
(i) Loop interchange
(ii) Dead-code elimination only
(iii) Common subexpression elimination
(iv) Register allocation

Worked SolutionAI Assisted

Answer: (iii) Common subexpression elimination

Explanation

Common subexpression elimination (CSE) detects an expression that was already computed and whose operands have not changed since, and reuses the earlier result instead of recomputing it.

Before:

x = a * b + c
y = a * b + d

After CSE:

t = a * b
x = t + c
y = t + d

The other options: loop interchange changes loop order (cache behaviour); dead-code elimination removes useless code; register allocation maps variables to registers.

(iii) Common subexpression elimination\boxed{\text{(iii) Common subexpression elimination}}

Similar questions

AI LearningWeb Platform

Coursify — Personal AI Course Generator

Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.