diff options
author | Thomas Lively <tlively@google.com> | 2023-01-12 12:38:38 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-12 10:38:38 -0800 |
commit | 51ac6ef642540d46af9b10869d047c8c6730a6c1 (patch) | |
tree | a747064e4c164c47b2cbc12cb75ea59312bf33d2 /src | |
parent | 4663321f956c5a4c0ceed2e7be7a81be57e8f921 (diff) | |
download | binaryen-51ac6ef642540d46af9b10869d047c8c6730a6c1.tar.gz binaryen-51ac6ef642540d46af9b10869d047c8c6730a6c1.tar.bz2 binaryen-51ac6ef642540d46af9b10869d047c8c6730a6c1.zip |
[Wasm GC] Generalize `skipCast` to work with all type hierarchies (#5422)
`skipCast` takes an optional parameter that bounds how general the resulting
type is allowed to be. That parameter previously had a default value of `anyref`
with the intention of allowing all casts to be skipped, but that default
inadvertently prevented any casts in the `func` or `extern` type hierarchies
from being skipped. Update `skipCast` so that the default parameter allows all
casts to be skipped in all hierarchies.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 6d4b7b674..bbb497f39 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1495,20 +1495,21 @@ struct OptimizeInstructions // |requiredType| is not provided we will accept any type there. // // See "notes on removing casts", above, for when this is safe to do. - void skipCast(Expression*& input, - Type requiredType = Type(HeapType::any, Nullable)) { + void skipCast(Expression*& input, Type requiredType = Type::none) { // Traps-never-happen mode is a requirement for us to optimize here. if (!getPassOptions().trapsNeverHappen) { return; } while (1) { if (auto* as = input->dynCast<RefAs>()) { - if (Type::isSubType(as->value->type, requiredType)) { + if (requiredType == Type::none || + Type::isSubType(as->value->type, requiredType)) { input = as->value; continue; } } else if (auto* cast = input->dynCast<RefCast>()) { - if (Type::isSubType(cast->ref->type, requiredType)) { + if (requiredType == Type::none || + Type::isSubType(cast->ref->type, requiredType)) { input = cast->ref; continue; } |