diff options
author | Alon Zakai <azakai@google.com> | 2021-08-09 17:25:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 17:25:11 -0700 |
commit | 0732425cd876127f22abd0a36e883caa5c8f7857 (patch) | |
tree | e0b54cac2edadd46e2ef23e04eca37be2677352c /src | |
parent | 86634774be6e060efec8f3048f82d61b8d91d5d7 (diff) | |
download | binaryen-0732425cd876127f22abd0a36e883caa5c8f7857.tar.gz binaryen-0732425cd876127f22abd0a36e883caa5c8f7857.tar.bz2 binaryen-0732425cd876127f22abd0a36e883caa5c8f7857.zip |
[Wasm GC] RefEq(x, null) => RefIsNull(x) (#4066)
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)); } } |