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?
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:
- Every assigned variable must have a unique name/subscript (each variable is defined exactly once).
- Every use of a variable must refer to the specific definition that reaches that use.
Let us trace the original code:
p = a - b: First assignment top. Introduce a new subscript, say .q = p * c: First assignment toq. This uses the current definition ofp() and assigns to a new version ofq, say : .p = u * v: Second assignment top. Becausepcannot be assigned twice in SSA, introduce a new subscript, say : .q = p + q: Second assignment toq. This must define a new version, say . The use ofpmust refer to the latest definition (), and the use ofqmust refer to the latest definition (): .
Option B represents this exact progression:
All four targets () are distinct, and all uses reference their correct reaching definitions.
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.