Fix example LVN pass's copy propagation on block inputs
Opened this issue · 0 comments
sampsyo commented
In the examples, lvn.py -p
currently fails for this example:
@main {
a: int = const 42;
.lbl:
b: int = id a;
a: int = const 5;
print b;
}
The optimization incorrectly changes the last line to print a
.
The problem is the interaction between copy (id
) propagation and basic block inputs (i.e., the fact that a
is read before it is written in the second block). One annoying but cleanish solution would be to copy a
to a fresh variable right as the block begins because it is read before it is written. Another, much less clean solution would be to detect the first overwrite of a
and do the renaming at that point, or to somehow avoid doing copy propagation for the id
because the value will be clobbered later.