swtv-kaist / cs458-fall22

1 stars 0 forks source link

[HW7] SSA in if-else statement #29

Open 3-24 opened 1 year ago

3-24 commented 1 year ago

I wonder if

int a;
if (condition) {
  a = 1;
} else {
  a = 2
}

is SSA form. I think it is okay because we know only one of a=1; and a=2; is executed. If we are using LLVM IR, then we can use the phi node to handle such cases. But the homework asks us to apply SSA on C code.

moonzoo commented 1 year ago

No. To convert the above code to a pure logic formula, both occurrences of a should be distinguished by using new names.

3-24 commented 1 year ago

Suppose we have a code with assertion.

int a;
if (condition) {
  a = 1;
} else {
  a = 2
}
assert(stmt)

For integer a, we can express the program logic into the following logic formula.

$$ ((condition \wedge (a = 1)) \vee (\neg condition \wedge (a = 2))) \wedge \neg stmt $$

Then, why do we need to distinguish two occurrences in this case?