IAE Academy

GATE 2026 CS1 Q.42: solution and answer

GATE 2026 · CS1Q.42 · 2 marks · MCQ

Consider the control flow graph shown in the figure.

Which one of the following options correctly lists the set of redundant expressions (common subexpressions) in the basic blocks B4 and B5?

Note: All the variables are integers.

GATE 2026 CS1 question 42: Control flow graph.Tap to open full size
Figure from the GATE 2026 CS1 paper. It is part of the question.
Figure description

Control flow graph. ENTRY -> B1. B1: a = b + i. B1 has edges to B2 and B3. B2: a = g * k, f = d - f, a = c * 4. B3: t = g * k, b = c + m. Both B2 and B3 have an edge to B4. B4: x = g * k, y = b + i. B4 -> B5. B5: z = c + m. B5 -> EXIT.

  1. (A)

    B4: { b + i }; B5: { c + m }

  2. (B)

    B4: { g * k }; B5: { c + m }

  3. (C)

    B4: { g * k, b + i }; B5: { }

  4. (D)

    B4: { g * k }; B5: { }

Answer and solution

ANSWER

Option (D): B4: { g * k }, B5: { }.

Official answer: DSource: Official answer key, GATE 2026 CS1 (IIT Guwahati)

  1. An expression is redundant at a point if it is available there: it has been computed on every path from ENTRY, and none of its operands has been redefined since.

  2. Available-expression equations: and , with .

  3. B1 has a = b + i. It generates . The variable is not an operand of any expression in play, so nothing is killed. .

  4. B2 has three statements. a = g * k generates . f = d - f generates and then kills it, because is redefined by the same statement. a = c * 4 generates . No statement redefines , , or , so survives. .

  5. B3 has t = g * k, which generates . Then b = c + m generates and kills , because is redefined. .

  6. . So g * k in B4 is redundant. b + i in B4 is not redundant, because on the path through B3 it was killed.

  7. B4 evaluates g * k (already available, nothing new generated) and b + i, which becomes available. Neither nor is an operand of any expression in play. , so .

  8. B5 computes c + m, which is not in . The path through B2 never computes . So B5 has no redundant expression.

  9. Result: B4: and B5: . This is option (D).

KEY IDEA

A common subexpression is redundant only if it is available on every path into the block. Available expressions use a forward "must" analysis, so IN is the intersection of the predecessors' OUT sets. An expression is killed when any of its operands is reassigned.

WATCH OUT FOR

Taking the union of the predecessors' OUT sets, instead of the intersection, makes and look redundant. They are not: is killed on the B3 path by b = c + m, and is computed only on the B3 path, never on the B2 path.

From the GATE 2026 CS1 paper. Every question of this paper · Download the full paper · All 6 Optimisation questions, with notes

More Optimisation questions