summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/type-updating.h13
-rw-r--r--src/passes/DeadCodeElimination.cpp6
2 files changed, 18 insertions, 1 deletions
diff --git a/src/ast/type-updating.h b/src/ast/type-updating.h
index 8063b3e59..c5f1d5344 100644
--- a/src/ast/type-updating.h
+++ b/src/ast/type-updating.h
@@ -266,6 +266,19 @@ struct TypeUpdater : public ExpressionStackWalker<TypeUpdater, UnifiedExpression
}
}
}
+
+ // efficiently update the type of an if, given the data we know. this
+ // can remove a concrete type and turn the if unreachable when it is
+ // unreachable
+ void maybeUpdateTypeToUnreachable(If* curr) {
+ if (!isConcreteWasmType(curr->type)) {
+ return; // nothing concrete to change to unreachable
+ }
+ curr->finalize();
+ if (curr->type == unreachable) {
+ propagateTypesUp(curr);
+ }
+ }
};
} // namespace wasm
diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp
index e5673a0cc..48fc4a91c 100644
--- a/src/passes/DeadCodeElimination.cpp
+++ b/src/passes/DeadCodeElimination.cpp
@@ -216,7 +216,7 @@ struct DeadCodeElimination : public WalkerPass<PostWalker<DeadCodeElimination>>
replaceCurrent(curr->condition);
}
// the if may have had a type, but can now be unreachable, which allows more reduction outside
- curr->finalize();
+ typeUpdater.maybeUpdateTypeToUnreachable(curr);
}
static void scan(DeadCodeElimination* self, Expression** currp) {
@@ -351,6 +351,10 @@ struct DeadCodeElimination : public WalkerPass<PostWalker<DeadCodeElimination>>
blockifyReachableOperands({ curr->value }, curr->type);
}
+ void visitSetGlobal(SetGlobal* curr) {
+ blockifyReachableOperands({ curr->value }, curr->type);
+ }
+
void visitLoad(Load* curr) {
blockifyReachableOperands({ curr->ptr }, curr->type);
}