diff options
author | Alon Zakai <azakai@google.com> | 2023-01-10 11:14:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 19:14:48 +0000 |
commit | 574ee5338f0fb28eb45ddcd4c2ee54cb67a0ea21 (patch) | |
tree | 3e09fa713657c3189fdec944c7bfa03eeea8bee3 /src | |
parent | 82e3eff9742c92e13aef25035b40488f5339618d (diff) | |
download | binaryen-574ee5338f0fb28eb45ddcd4c2ee54cb67a0ea21.tar.gz binaryen-574ee5338f0fb28eb45ddcd4c2ee54cb67a0ea21.tar.bz2 binaryen-574ee5338f0fb28eb45ddcd4c2ee54cb67a0ea21.zip |
[Wasm GC] Optimize ref.as_non_null of a nullable cast (#5415)
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 3265a1240..6ca314b96 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -2219,6 +2219,22 @@ struct OptimizeInstructions if (curr->op == RefAsNonNull && !curr->value->type.isNullable()) { replaceCurrent(curr->value); + return; + } + + // As we do in visitRefCast, ref.cast can be combined with ref.as_non_null. + // This code handles the case where the ref.as is on the outside: + // + // (ref.as_non_null (ref.cast null ..)) + // => + // (ref.cast ..) + // + if (auto* cast = curr->value->dynCast<RefCast>()) { + // The cast cannot be non-nullable, or we would have handled this right + // above by just removing the ref.as, since it would not be needed. + assert(!cast->type.isNonNullable()); + cast->type = Type(cast->type.getHeapType(), NonNullable); + replaceCurrent(cast); } } |