staticafi/llvm2c

Misplaced PHI variables

mchalupa opened this issue · 1 comments

addPhis should add reading PHI variables at the end of the incoming block. It does that, but the problem is that the block may be empty at the time of adding the reads, so it ends up in having the reads at the beginning of the block (as the instructions from that block are added later).

Happens with this program: https://github.com/sosy-lab/sv-benchmarks/blob/master/c/bitvector/gcd_1.c when compiled with optimizations and mem2reg pass.

The problem is, that an if statement is created from a br, which is added after adding phis. addPhis happens before parseBreaks. The condition is then inlined into the if statement, so phi assignments happen before the condition using them is evaluated.

The fix will be, that the condition will be evaluated and stored into a variable before phi assignment (which is supposed to be at the end of the block) happens. <-- this doesn't work as intended.