Question

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
Official answer and solution
Official answer
B
From
Official GATE 2017 answer key

Solution

Apply the principles of Static Single Assignment (SSA) form, where every variable is assigned exactly once and uses refer to the most recent version.

In Static Single Assignment (SSA) form:

  1. Every assigned variable must have a unique name/subscript (each variable is defined exactly once).
  2. Every use of a variable must refer to the specific definition that reaches that use.

Let us trace the original code:

  1. p = a - b: First assignment to p. Introduce a new subscript, say p3p_3.
  2. q = p * c: First assignment to q. This uses the current definition of p (p3p_3) and assigns to a new version of q, say q4q_4: q4=p3∗cq_4 = p_3 * c.
  3. p = u * v: Second assignment to p. Because p cannot be assigned twice in SSA, introduce a new subscript, say p4p_4: p4=u∗vp_4 = u * v.
  4. q = p + q: Second assignment to q. This must define a new version, say q5q_5. The use of p must refer to the latest definition (p4p_4), and the use of q must refer to the latest definition (q4q_4): q5=p4+q4q_5 = p_4 + q_4.

Option B represents this exact progression:

p3=a−bp_3 = a - b
q4=p3∗cq_4 = p_3 * c
p4=u∗vp_4 = u * v
q5=p4+q4q_5 = p_4 + q_4

All four targets (p3,q4,p4,q5p_3, q_4, p_4, q_5) are distinct, and all uses reference their correct reaching definitions.

Final answer

B

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 1
Question
12 of 65, printed as CS Q.12
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.