diff options
author | Alon Zakai <azakai@google.com> | 2020-01-10 06:37:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-10 06:37:00 -0800 |
commit | 263d2d5025c98092f781c8b8d9eb7ac6df6aadab (patch) | |
tree | 4994c331c247a7c78d241f655b10a93e59027593 /src | |
parent | 98747d97f089354091d115fb300006f3cc506a0c (diff) | |
download | binaryen-263d2d5025c98092f781c8b8d9eb7ac6df6aadab.tar.gz binaryen-263d2d5025c98092f781c8b8d9eb7ac6df6aadab.tar.bz2 binaryen-263d2d5025c98092f781c8b8d9eb7ac6df6aadab.zip |
wasm2js: Do not convert x >>> 0 | 0 to x >>> 0 (#2581)
isBinary was used where we should only accept
a signed binary, as removing the | 0 from an unsigned
value may be incorrect.
This does regress a few small things (as can be seen
in the diff). If it's important we can add more sophisticated
optimizations here, perhaps like an assumption that the
signedness of a local never matters.
Fixes emscripten-core/emscripten#10173
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm2js.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 06ab81263..e7b62c16a 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -179,6 +179,14 @@ static void optimizeJS(Ref ast) { return false; }; + auto isSignedBitwise = [](Ref node) { + if (node->isArray() && !node->empty() && node[0] == BINARY) { + auto op = node[1]; + return op == OR || op == AND || op == XOR || op == RSHIFT || op == LSHIFT; + } + return false; + }; + auto isUnary = [](Ref node, IString op) { return node->isArray() && !node->empty() && node[0] == UNARY_PREFIX && node[1] == op; @@ -275,9 +283,9 @@ static void optimizeJS(Ref ast) { // x | 0 going into a bitwise op => skip the | 0 node[2] = removeOrZero(node[2]); node[3] = removeOrZero(node[3]); - // x | 0 | 0 => x | 0 + // (x | 0 or similar) | 0 => (x | 0 or similar) if (isOrZero(node)) { - if (isBitwise(node[2])) { + if (isSignedBitwise(node[2])) { replaceInPlace(node, node[2]); } } |