Compilers
Converting the code above to SSA form inserts an expression like "x3 = φ(x1, x2)" after the if statement. What does the φ function do?
if (c) x = 1;
else x = 2;
y = x + 3;
- AIt returns the larger of x1 and x2
- BIt computes and returns the sum of x1 and x2
- CIt picks x1 or x2 by the incoming path
Show answer and explanation
Answer: C. It picks x1 or x2 by the incoming path
In SSA form the then-branch assignment becomes x1 and the else-branch assignment x2, so after the join the computation of y must specify which x to use. A φ function denotes selecting a value at a join point: x1 if control arrived from the then side, x2 if from the else side. Real machine code has no φ instruction; it is eventually replaced by register copies or similar. It has nothing to do with comparing or adding values.
- A. It does not choose by magnitude.
- B. It does not add the values.
- C. Correct. It selects a value according to the incoming path.