GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 46

GATE CSE 2015 Set 1 Q46

Compiler Design · Code Optimization & Data-Flow Analysis · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q46 2 marks · MCQ
Report issue

Code Optimization & Data-Flow Analysis

Question 46, GATE 2015: A variable is live at statement Si if some reachable use Sj has no intervening assignment, including Si and Sj. CFG: block 1 p=q+r; s=p+q; u=s*v; branches to block 2 v=r+u or block 3 q=s*u; both go to block 4 q=v+r; block 4 loops to block 1. Which are live at both block 2 and block 3 entry? A p,s,u; B r,s,u; C r,u; D q,v.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Use the old value test: a value matters only if a path reads it before replacement. At block 2, r and u are read immediately; old v is killed by v=r+u, old q by block 4, and p,s by block 1 before future use. At block 3, s,u are immediate reads and v,r remain needed at block 4. Taking the intersection of {r,u} and {s,u,v,r} leaves {r,u}. Liveness is backward data flow and uses possible paths, not just values read in the next line.

Solution: At entry to block 2, r and u are used by v=r+u; old v is overwritten and old q is overwritten in block 4. At entry to block 3, s and u are used by q=s*u, while v and r are needed by block 4. Thus live-in sets are{r, u} and{s, u, v, r}; their intersection is{r, u}, C. Values overwritten in block 1 before any later use need not be added.

Original paper, page 17 · Answer key