diff options
author | Alon Zakai <azakai@google.com> | 2023-01-05 11:31:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 19:31:28 +0000 |
commit | 0293c4649204e11f7db5724dc9477aa1ef6aef18 (patch) | |
tree | 0159a76f9ec44d7836de8f5ed42666a448f4e993 /src | |
parent | a090dcf453a701922ee6e5cfecdf5619ab6a023b (diff) | |
download | binaryen-0293c4649204e11f7db5724dc9477aa1ef6aef18.tar.gz binaryen-0293c4649204e11f7db5724dc9477aa1ef6aef18.tar.bz2 binaryen-0293c4649204e11f7db5724dc9477aa1ef6aef18.zip |
[Wasm GC] Turn casts non-nullable when they lead to a trap on null anyhow (#5395)
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 6b2a5a1cd..c2142fe6c 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1595,6 +1595,21 @@ struct OptimizeInstructions } } + // A nullable cast can be turned into a non-nullable one: + // + // (struct.get ;; or something else that traps on a null ref + // (ref.cast null + // => + // (struct.get + // (ref.cast ;; now non-nullable + // + // Either way we trap here, but refining the type may have benefits later. + if (ref->type.isNullable()) { + if (auto* cast = ref->dynCast<RefCast>()) { + cast->type = Type(cast->type.getHeapType(), NonNullable); + } + } + auto fallthrough = Properties::getFallthrough(ref, getPassOptions(), *getModule()); |