diff --git a/teavm-core/src/main/java/org/teavm/optimization/ClassSetOptimizer.java b/teavm-core/src/main/java/org/teavm/optimization/ClassSetOptimizer.java index 3a67b82c7..1faca0b76 100644 --- a/teavm-core/src/main/java/org/teavm/optimization/ClassSetOptimizer.java +++ b/teavm-core/src/main/java/org/teavm/optimization/ClassSetOptimizer.java @@ -36,8 +36,7 @@ public class ClassSetOptimizer { } private List getOptimizations() { - // TODO: repair CommonSubexpressionElimination and get it back here - return Arrays.asList(new UnusedVariableElimination()); + return Arrays.asList(new GlobalValueNumbering(), new UnusedVariableElimination()); } public void optimizeAll(ListableClassHolderSource classSource) { diff --git a/teavm-core/src/main/java/org/teavm/optimization/CommonSubexpressionElimination.java b/teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java similarity index 99% rename from teavm-core/src/main/java/org/teavm/optimization/CommonSubexpressionElimination.java rename to teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java index eb95f54da..550734318 100644 --- a/teavm-core/src/main/java/org/teavm/optimization/CommonSubexpressionElimination.java +++ b/teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java @@ -30,7 +30,7 @@ import org.teavm.model.util.ProgramUtils; * * @author Alexey Andreev */ -public class CommonSubexpressionElimination implements MethodOptimization { +public class GlobalValueNumbering implements MethodOptimization { private Map knownValues = new HashMap<>(); private boolean eliminate; private int[] map; @@ -137,7 +137,7 @@ public class CommonSubexpressionElimination implements MethodOptimization { private void bind(int var, String 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; map[var] = known.value; } else {