GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 47

GATE CSE 2015 Set 1 Q47

Compiler Design · Intermediate Code · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q47 2 marks · NAT
Report issue

Intermediate Code

Question 47, GATE 2015: Find the least temporary-variable count for static-single-assignment three-address code for q+r/3+s−t*5+u*v/w.
Tap to enlarge
Answer & solution

Official answer: 8

One valid translation is t1=r/3; t2=q+t1; t3=t2+s; t4=t*5; t5=t3−t4; t6=u*v; t7=t6/w; t8=t5+t7. There are eight binary-operation nodes and each three-address instruction computes only one. SSA forbids assigning a later intermediate into an already used temporary name, so the intended unoptimized translation needs eight names, including its final result. Reusing one scratch register would not be SSA.

Solution: The expression has eight binary operations: the divisions r/3 and (u*v)/w, multiplications t*5 and u*v, and four outer additive/subtractive operations. A three-address translation with a fresh temporary for every operation therefore uses eight temporaries, including the expression result.

Original paper, page 17 · Answer key