Repairs common subexpression elimination and renames it to global value

numbering, as it is really pessimistic GVN
This commit is contained in:
konsoletyper 2014-03-07 23:13:07 +04:00
parent 4b624d8027
commit 4143e6c8d7
2 changed files with 3 additions and 4 deletions

View File

@ -36,8 +36,7 @@ public class ClassSetOptimizer {
} }
private List<MethodOptimization> getOptimizations() { private List<MethodOptimization> getOptimizations() {
// TODO: repair CommonSubexpressionElimination and get it back here return Arrays.<MethodOptimization>asList(new GlobalValueNumbering(), new UnusedVariableElimination());
return Arrays.<MethodOptimization>asList(new UnusedVariableElimination());
} }
public void optimizeAll(ListableClassHolderSource classSource) { public void optimizeAll(ListableClassHolderSource classSource) {

View File

@ -30,7 +30,7 @@ import org.teavm.model.util.ProgramUtils;
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public class CommonSubexpressionElimination implements MethodOptimization { public class GlobalValueNumbering implements MethodOptimization {
private Map<String, KnownValue> knownValues = new HashMap<>(); private Map<String, KnownValue> knownValues = new HashMap<>();
private boolean eliminate; private boolean eliminate;
private int[] map; private int[] map;
@ -137,7 +137,7 @@ public class CommonSubexpressionElimination implements MethodOptimization {
private void bind(int var, String value) { private void bind(int var, String value) {
KnownValue known = knownValues.get(value); KnownValue known = knownValues.get(value);
if (known != null && domTree.dominates(known.location, currentBlockIndex)) { if (known != null && domTree.dominates(known.location, currentBlockIndex) && known.value != var) {
eliminate = true; eliminate = true;
map[var] = known.value; map[var] = known.value;
} else { } else {