rwallace
rwallace

Reputation: 33365

Semantics of SSA and multiple assignment

In SSA form, a variable assigned from a phi ends up with the appropriate value depending on which path it was reached by. But what happens if, perhaps via some unusual path, both inputs to the phi have been assigned? e.g.

a = 1
...
b = 2
...
c = phi(a, b)

Is it defined to behave like a union such that c ends up with the value 2 because that was the last assignment?

Upvotes: 1

Views: 379

Answers (1)

Kun Ling
Kun Ling

Reputation: 2219

For SSA (Single Static Assignment), the two operand of a phi node should be two definition of a specific variable.

For your example, that means b=2, and a=1 are two definition for a single variable. And since b=2 will always run after a=1. Therefore, The definition b=2 will kill the definition of a=1. So, your phi(a,b) is in fact illegal.

phi's operands usually are definitions from two different execution pass of the program.

Upvotes: 5

Related Questions