GATE / CS ARCHIVE

GATE CSE 2026 SET 1 / QUESTION 42

Available expressions at a control-flow merge

Compiler Design · Code Optimization & Data-Flow Analysis · Full GATE CSE 2026 Set 1 paper

GATE 2026 Set 1, Q42 2 marks · MCQ
Report issue

Code Optimization & Data-Flow Analysis

Question 42, GATE 2026: The flow is Entry→B1→either B2 or B3→B4→B5→Exit. B1: a=b+i. B2: a=g*k; f=d−f; a=c*4. B3: t=g*k; b=c+m. B4: x=g*k; y=b+i. B5: z=c+m. All variables are integers. Find the redundant expression sets in B4 and B5.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Givens and goal

The flow is Entry→B1→either B2 or B3→B4→B5→Exit. B1: a=b+i. B2: a=g*k; f=d−f; a=c*4. B3: t=g*k; b=c+m. B4: x=g*k; y=b+i. B5: z=c+m. All variables are integers. Find the redundant expression sets in B4 and B5.

Approach

An expression is available only if it has already been computed on every incoming path and neither operand has been reassigned since.

Step-by-step solution

1. The control-flow shape is a diamond followed by a tail:

    B1 ──→ B2 ──┐
      └──→ B3 ──┴──→ B4 ──→ B5

At the B4 merge, availability uses the intersection of the incoming expression sets, not their union.
2. B1 computes b+i. Along B2 neither b nor i is assigned, so this expression remains available there. Along B3, however, b is overwritten by c+m. That kills the old b+i value. Hence b+i is not available on every path to B4 and y=b+i is not globally redundant.
3. Both B2 and B3 compute g*k, and neither subsequently changes g or k. Thus g*k is available along both incoming paths. Its evaluation in x=g*k is redundant. B2 later overwrites a, but that changes the destination holding a previous result, not the operands g and k; a transformation may preserve the value in a temporary.
4. B3 computes c+m, but B2 does not. B4 computes neither c+m nor anything proving its value was previously computed on the B2 path. Therefore z=c+m in B5 is not redundant on all paths.
5. The required sets are B4:{g*k}, B5:empty, option D. Option A wrongly keeps b+i; B wrongly treats a computation on only one branch as universally available; C also incorrectly keeps b+i.

In particular a=c*4 assigns a, not c; the target variable matters when deciding whether an expression is killed.

Original paper, page 31 · Answer key