Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q12 — Intermediate Code Generation

Explain with AI

Consider the following intermediate program in three address code

p = a - b
q = p * c
p = u * v
q = p + q

Which one of the following corresponds to a static single assignment form of the above code?

Choose one option
View worked solution

Answer: B

In Static Single Assignment (SSA) form, the following two rules must be satisfied:

  1. Each variable is assigned exactly once.
  2. Every variable must be defined before it is used in any expression.

Let's convert the given intermediate code step-by-step by subscripting the variables to ensure unique definitions:

  1. Statement 1: p = a - b
    This is the first definition of p. Let's name this version p3p_3.
    p3=a−b\mathbf{p_3 = a - b}
  2. Statement 2: q = p * c
    This is the first definition of q. Let's name this version q4q_4. The p on the right-hand side refers to the most recent definition of p, which is p3p_3.
    q4=p3∗c\mathbf{q_4 = p_3 * c}
  3. Statement 3: p = u * v
    This is a new definition of p. We must use a new version name, say p4p_4.
    p4=u∗v\mathbf{p_4 = u * v}
  4. Statement 4: q = p + q
    This is a new definition of q. We name this version q5q_5.
    • The p on the right-hand side refers to the most recent definition of p, which is p4p_4.
    • The q on the right-hand side refers to the most recent definition of q, which is q4q_4.
    q5=p4+q4\mathbf{q_5 = p_4 + q_4}

Combining these, the valid SSA form is:

p3 = a  - b
q4 = p3 * c
p4 = u  * v
q5 = p4 + q4

This matches Option B.

Elimination of other options:

  • Option A: Both p1 and q1 are assigned multiple times, violating the single assignment rule.
  • Option C: Variables p2, p4, and q3 are used on the right-hand side without being defined first.
  • Option D: The original un-subscripted variables p and q are used on the right-hand side instead of their SSA-defined versions.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Intermediate Code Generation questions