summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-10-28 16:48:02 -0700
committerGitHub <noreply@github.com>2021-10-28 16:48:02 -0700
commit25264f7be10ebead4c464a218bf32a2456bb1cd9 (patch)
treed13253f66791bd063ddd374e5025b8a2303e145c /src
parent446d97617f02aecf83153fe70f2cc447a9f5cf42 (diff)
downloadbinaryen-25264f7be10ebead4c464a218bf32a2456bb1cd9.tar.gz
binaryen-25264f7be10ebead4c464a218bf32a2456bb1cd9.tar.bz2
binaryen-25264f7be10ebead4c464a218bf32a2456bb1cd9.zip
Heap2Local: Handle loops (#4288)
When the allocation we optimize away flows through a loop, then just like with a block we must change the type to be nullable, since we are replacing the allocation with a null. Fixes #4287
Diffstat (limited to 'src')
-rw-r--r--src/passes/Heap2Local.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/passes/Heap2Local.cpp b/src/passes/Heap2Local.cpp
index ac6fb49a6..fc3c18db0 100644
--- a/src/passes/Heap2Local.cpp
+++ b/src/passes/Heap2Local.cpp
@@ -274,12 +274,14 @@ struct Heap2LocalOptimizer {
// left to other passes, like getting rid of dropped code without side
// effects.
- void visitBlock(Block* curr) {
+ // Adjust the type that flows through an expression, updating that type as
+ // necessary.
+ void adjustTypeFlowingThrough(Expression* curr) {
if (!reached.count(curr)) {
return;
}
- // Our allocation passes through this block. We must turn its type into a
+ // Our allocation passes through this expr. We must turn its type into a
// nullable one, because we will remove things like RefAsNonNull of it,
// which means we may no longer have a non-nullable value as our input,
// and we could fail to validate. It is safe to make this change in terms
@@ -290,6 +292,10 @@ struct Heap2LocalOptimizer {
curr->type = Type(curr->type.getHeapType(), Nullable);
}
+ void visitBlock(Block* curr) { adjustTypeFlowingThrough(curr); }
+
+ void visitLoop(Loop* curr) { adjustTypeFlowingThrough(curr); }
+
void visitLocalSet(LocalSet* curr) {
if (!reached.count(curr)) {
return;