summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-11-02 13:10:46 -0700
committerGitHub <noreply@github.com>2022-11-02 13:10:46 -0700
commitc5f5cdd79cafa003d2cffafcbf59f08c4095eac6 (patch)
tree67607e5a733a2fe6ba5f4dd60f67d92affe61f46 /src
parent25e5aa67bd16f277ad32d42bfbbf7cd130ddf028 (diff)
downloadbinaryen-c5f5cdd79cafa003d2cffafcbf59f08c4095eac6.tar.gz
binaryen-c5f5cdd79cafa003d2cffafcbf59f08c4095eac6.tar.bz2
binaryen-c5f5cdd79cafa003d2cffafcbf59f08c4095eac6.zip
SimplifyLocals: Fix handling of subtyping (#5210)
We just checked if the new type we prefer (when switching a local to a more refined one in #5194) is different than the old type. But that check at the end must check it is a subtype as well. Diff without whitespace is smaller.
Diffstat (limited to 'src')
-rw-r--r--src/passes/SimplifyLocals.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index c368740f1..7e3b33824 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -1091,24 +1091,28 @@ struct SimplifyLocals
}
assert(best != Index(-1));
// Due to ordering, the best index may be different from us but have
- // the same # of locals - make sure we actually improve.
+ // the same # of locals - make sure we actually improve, either adding
+ // more gets, or a more refined type (and never change to a less
+ // refined type).
auto bestType = func->getLocalType(best);
auto oldType = func->getLocalType(curr->index);
- if (best != curr->index && (getNumGetsIgnoringCurr(best) >
- getNumGetsIgnoringCurr(curr->index) ||
- bestType != oldType)) {
- // Update the get counts.
- (*numLocalGets)[best]++;
- assert((*numLocalGets)[curr->index] >= 1);
- (*numLocalGets)[curr->index]--;
- // Make the change.
- curr->index = best;
- anotherCycle = true;
- if (bestType != oldType) {
- curr->type = func->getLocalType(best);
- // We are switching to a more refined type, which might require
- // changes in the user of the local.get.
- refinalize = true;
+ if (best != curr->index && Type::isSubType(bestType, oldType)) {
+ auto hasMoreGets = getNumGetsIgnoringCurr(best) >
+ getNumGetsIgnoringCurr(curr->index);
+ if (hasMoreGets || bestType != oldType) {
+ // Update the get counts.
+ (*numLocalGets)[best]++;
+ assert((*numLocalGets)[curr->index] >= 1);
+ (*numLocalGets)[curr->index]--;
+ // Make the change.
+ curr->index = best;
+ anotherCycle = true;
+ if (bestType != oldType) {
+ curr->type = func->getLocalType(best);
+ // We are switching to a more refined type, which might require
+ // changes in the user of the local.get.
+ refinalize = true;
+ }
}
}
}