diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 7d9111e0b..51a2095ea 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1121,6 +1121,18 @@ struct OptimizeInstructions if (areConsecutiveInputsEqual(curr->left, curr->right)) { replaceCurrent( Builder(*getModule()).makeConst(Literal::makeOne(Type::i32))); + return; + } + + // Canonicalize to the pattern of a null on the right-hand side, if there is + // one. This makes pattern matching simpler. + if (curr->left->is<RefNull>()) { + std::swap(curr->left, curr->right); + } + + // RefEq of a value to Null can be replaced with RefIsNull. + if (curr->right->is<RefNull>()) { + replaceCurrent(Builder(*getModule()).makeRefIs(RefIsNull, curr->left)); } } |