The common subexpression elimination stage currently has a bug, where if multiple eliminated subexpressions depend on each other are inserted in the wrong order into a basic block.
This can result in transformation like this:
print("%d", a * 2);
print("%d", a * 2 + 5);
print("%d", a * 2 + 5);
int c0 = c1 + 5;
int c1 = a * 2;
print("%d", c0);
print("%d", c0);
print("%d", c1);
This is caused by us caching the index of each instruction in the CfgInstruction class and not updating it after inserting new definitions. This PR simply changes this so that the index is always calculated instead of being cached. While theoretically this has worse performance, the extend tests runtime only increased from 10:42 to 11:13 on my machine.
The common subexpression elimination stage currently has a bug, where if multiple eliminated subexpressions depend on each other are inserted in the wrong order into a basic block.
This can result in transformation like this:
This is caused by us caching the index of each instruction in the
CfgInstruction
class and not updating it after inserting new definitions. This PR simply changes this so that the index is always calculated instead of being cached. While theoretically this has worse performance, the extend tests runtime only increased from 10:42 to 11:13 on my machine.