From 8ce104ae640d0d328d0e43a49c0945156055995e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 3 Oct 2024 19:36:44 +0200 Subject: [PATCH] Fix bug in GVN that prevented optimizations in same basic block --- .../org/teavm/model/optimization/GlobalValueNumbering.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java b/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java index c048c8b79..27bd008e4 100644 --- a/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java +++ b/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java @@ -219,8 +219,7 @@ public class GlobalValueNumbering implements MethodOptimization { } namesCompatible = knownName.isEmpty() || name.isEmpty() || knownName.equals(name); } - if (known != null && domTree.dominates(known.location * 2 + 1, currentBlockIndex * 2) && known.value != var - && namesCompatible) { + if (known != null && dominates(known.location, currentBlockIndex) && known.value != var && namesCompatible) { map[var] = known.value; if (!noReplace) { replaceMap[var] = known.value; @@ -242,6 +241,10 @@ public class GlobalValueNumbering implements MethodOptimization { } } + private boolean dominates(int a, int b) { + return a == b || domTree.dominates(a * 2 + 1, b * 2); + } + private InstructionVisitor constantPreprocessor = new AbstractInstructionVisitor() { private void setConstant(int index, Number value) { numericConstants[index] = value;