diff options
author | Thomas Lively <tlively@google.com> | 2023-08-17 14:47:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 14:47:02 -0700 |
commit | 7abe224ab5c00fa471e3f4e1ed176974b8ac4e9b (patch) | |
tree | 6dafb705a4f5ee3570c3c610a2eef777d9a7efcd /src | |
parent | 67dd6f7db409f9ab7171e97db9da2a4e01a5dc4b (diff) | |
download | binaryen-7abe224ab5c00fa471e3f4e1ed176974b8ac4e9b.tar.gz binaryen-7abe224ab5c00fa471e3f4e1ed176974b8ac4e9b.tar.bz2 binaryen-7abe224ab5c00fa471e3f4e1ed176974b8ac4e9b.zip |
Further improve ref.cast during finalization (#5882)
We previously improved the nullability and heap type of the ref.cast target type
in RefCast::finalize() based on what we knew about its input type. Simplify the
code and make this improvement more powerful by using the greatest lower bound
of the original cast target and input type.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 648a25d9e..74b944bb6 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -948,23 +948,18 @@ void RefCast::finalize() { return; } - // Do not unnecessarily lose non-nullability info. We could leave this for - // optimizations, but doing it here as part of finalization/refinalization - // ensures that type information flows through in an optimal manner and can be - // used as soon as possible. - if (ref->type.isNonNullable() && type.isNullable()) { - type = Type(type.getHeapType(), NonNullable); - } - - // Do not unnecessarily lose heap type info, as above for nullability. Note - // that we must check if the ref has a heap type, as we reach this before - // validation, which will error if the ref does not in fact have a heap type. - // (This is a downside of propagating type information here, as opposed to - // leaving it for an optimization pass.) - if (ref->type.isRef() && - HeapType::isSubType(ref->type.getHeapType(), type.getHeapType())) { - type = Type(ref->type.getHeapType(), type.getNullability()); + // We reach this before validation, so the input type might be totally wrong. + // Return early in this case to avoid doing the wrong thing below. + if (!ref->type.isRef()) { + return; } + + // Do not unnecessarily lose type information. We could leave this for + // optimizations (and indeed we do a more powerful version of this in + // OptimizeInstructions), but doing it here as part of + // finalization/refinalization ensures that type information flows through in + // an optimal manner and can be used as soon as possible. + type = Type::getGreatestLowerBound(type, ref->type); } void BrOn::finalize() { |