diff options
author | Alon Zakai <azakai@google.com> | 2022-02-24 17:09:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-25 01:09:05 +0000 |
commit | 0fe26e71ac1c5b22b990ea9b73131b49b1e9e22a (patch) | |
tree | fbc3eb5f15afd10a27b5ad42a9051ee2a19678d7 /src | |
parent | 11ada63fbb7ba982c92f22fa1fb0e39cebe3f194 (diff) | |
download | binaryen-0fe26e71ac1c5b22b990ea9b73131b49b1e9e22a.tar.gz binaryen-0fe26e71ac1c5b22b990ea9b73131b49b1e9e22a.tar.bz2 binaryen-0fe26e71ac1c5b22b990ea9b73131b49b1e9e22a.zip |
[Wasm GC] Optimize static casts in br_on_cast* (#4520)
We were missing this particular case, which we can in fact handle
when the cast is static.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/gc-type-utils.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/ir/gc-type-utils.h b/src/ir/gc-type-utils.h index 80a935462..584cde83c 100644 --- a/src/ir/gc-type-utils.h +++ b/src/ir/gc-type-utils.h @@ -52,9 +52,19 @@ inline EvaluationResult evaluateKindCheck(Expression* curr) { // We don't check nullability here. case BrOnNull: case BrOnNonNull: - // Casts can only be known at runtime using RTTs. - case BrOnCast: case BrOnCastFail: + flip = true; + [[fallthrough]]; + case BrOnCast: + if (!br->rtt) { + // This is a static cast check, which we may be able to resolve at + // compile time. Note that the type must be non-nullable for us to + // succeed at that inference, as otherwise a null can make us fail. + if (Type::isSubType(br->ref->type, + Type(br->intendedType, NonNullable))) { + return flip ? Failure : Success; + } + } return Unknown; case BrOnNonFunc: flip = true; |