From 4143e6c8d7cc3cdf4d7cc009a94a41869a6c1896 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Fri, 7 Mar 2014 23:13:07 +0400 Subject: [PATCH] Repairs common subexpression elimination and renames it to global value numbering, as it is really pessimistic GVN --- .../main/java/org/teavm/optimization/ClassSetOptimizer.java | 3 +-- ...ubexpressionElimination.java => GlobalValueNumbering.java} | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) rename teavm-core/src/main/java/org/teavm/optimization/{CommonSubexpressionElimination.java => GlobalValueNumbering.java} (99%) 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 {