edited by
1,920 views
9 votes
9 votes
$x=5$

$x=x-3$

$\textbf{if } x<3$

$\quad y=x*2$

$\quad w=y$

$\textbf{else}$

$\quad y=x-3$

$w=x-y$

$z=x+y$

Give Equivalent SSA.
edited by

1 Answer

Best answer
7 votes
7 votes

SSA requires that each variable is assigned exactly once,i.e, the variable cannot be repeated on the LHS of assignment.

For the above Code Snippet, Equivalent SSA is

R1 = 5
R2 = R1 - 3

/* In the Below lines Y may have either R3 or R5 depending on which block executes,
But just that there blocks are different and at a time only one Block executes does not mean,
that they have a same value R3 in both the blocks */

if (R2 < 3)               // This is not LHS of assignment, hence same LHS
{
    R3 = R2 * 2        // Here, Y same but due to SSA, LHS must be different
    R4 = R3
}
else
{
    R5 = R2 - 3        //Here, Y same but due to SSA, LHS must be different
}

/* In the Below lines Y may have either R3 or R5 depending on which block executes */

R6 = (R3,R5) 
R7 = R2 - R6           
R8 = R2 + R7         
selected by

Related questions

0 votes
0 votes
1 answer
2
minal asked Jan 22, 2019
893 views
# of temporary variable required to create 3 address code in static single assignment form for the expression P+Q*R-S/(Q*R).