summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 97f1cb756..ed3d474d9 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1054,8 +1054,12 @@ struct OptimizeInstructions
// can't remove or move a ref.as_non_null flowing into a local.set/tee, and
// (2) even if the local were nullable, if we change things we might prevent
// the LocalSubtyping pass from turning it into a non-nullable local later.
+ // Note that we must also check if this local is nullable regardless, as a
+ // parameter might be non-nullable even if nullable locals are disallowed
+ // (as that just affects vars, and not params).
if (auto* as = curr->value->dynCast<RefAs>()) {
- if (as->op == RefAsNonNull && !getModule()->features.hasGCNNLocals()) {
+ if (as->op == RefAsNonNull && !getModule()->features.hasGCNNLocals() &&
+ getFunction()->getLocalType(curr->index).isNullable()) {
// (local.tee (ref.as_non_null ..))
// =>
// (ref.as_non_null (local.tee ..))