Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q19 — Data Flow Analyses: Constant Propagation, Liveness, CSE

Explain with AI

Consider the following code segment.

x = u - t;
y = x * v; 
x = y + w;
y = t - z; 
y = x * y;

The minimum number of total variables required to convert the above code segment to static single assignment form is __________.

View worked solution

Answer: 10

To convert the given code segment into Static Single Assignment (SSA) form, every variable must be assigned exactly once, and every variable must be defined before it is used.

Step 1: Identify the Input Variables

The variables that are read but not defined within this block are the input variables:

  • u,t,v,w,zu, t, v, w, z

This gives 5 input variables.

Step 2: Version the Assigned Variables

We now version each assignment to xx and yy so that each version is assigned exactly once:

  1. x = u - t; → x1=u−tx_1 = u - t
  2. y = x * v; → y1=x1imesvy_1 = x_1 imes v
  3. x = y + w; → x2=y1+wx_2 = y_1 + w
  4. y = t - z; → y2=t−zy_2 = t - z
  5. y = x * y; → y3=x2imesy2y_3 = x_2 imes y_2

Step 3: Count the Total Variables

Let's list all the distinct variables present in the SSA form:

  • Inputs: u,t,v,w,zu, t, v, w, z (5 variables)
  • SSA versions of xx: x1,x2x_1, x_2 (2 variables)
  • SSA versions of yy: y1,y2,y3y_1, y_2, y_3 (3 variables)

Total variables=5+2+3=10\text{Total variables} = 5 + 2 + 3 = 10

Thus, the minimum number of total variables required is 10.

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

Published
Report a correction
Keep exploringMore Data Flow Analyses: Constant Propagation, Liveness, CSE questions