diff options
Diffstat (limited to 'src/passes/RemoveUnusedBrs.cpp')
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 88a87ba1f..5631c9d5f 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -389,10 +389,9 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { // First, check for a possible null which would prevent all other // optimizations. - // (Note: if the spec had BrOnNonNull, instead of BrOnNull, then we could - // replace a br_on_func whose input is (ref null func) with br_on_non_null, - // as only the null check would be needed. But as things are, we cannot do - // such a thing.) + // TODO: Look into using BrOnNonNull here, to replace a br_on_func whose + // input is (ref null func) with br_on_non_null (as only the null check + // would be needed). auto refType = curr->ref->type; if (refType.isNullable()) { return; @@ -405,6 +404,12 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { anotherCycle = true; return; } + if (curr->op == BrOnNonNull) { + // This cannot be null, so the br is always taken. + replaceCurrent(Builder(*getModule()).makeBreak(curr->name, curr->ref)); + anotherCycle = true; + return; + } // Check if the type is the kind we are checking for. auto result = GCTypeUtils::evaluateKindCheck(curr); |