summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2019-08-26 12:40:38 -0700
committerGitHub <noreply@github.com>2019-08-26 12:40:38 -0700
commitf070e8c10a15a02735fbd9b88c4c569a8c786933 (patch)
tree414519c4d3561908f130091c36ffe22592fc6dcb /src
parent84da536f584a11edd2c6d9d7d422e917df0e0155 (diff)
downloadbinaryen-f070e8c10a15a02735fbd9b88c4c569a8c786933.tar.gz
binaryen-f070e8c10a15a02735fbd9b88c4c569a8c786933.tar.bz2
binaryen-f070e8c10a15a02735fbd9b88c4c569a8c786933.zip
Do not hoist truncation of wasm2js divisions (#2305)
It is not valid to defer the truncation of divisions because accumulated non-integral results can produce different values when they are combined before truncation. This was causing a test failure in the Rust test suite.
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm2js.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index 2007a65d8..ebed16226 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -353,11 +353,13 @@ static void optimizeJS(Ref ast) {
} else if (isUnary(node, L_NOT)) {
node[2] = optimizeBoolean(node[2]);
}
- // Add/subtract can merge coercions up.
+ // Add/subtract can merge coercions up, except when a child is a division,
+ // which needs to be eagerly truncated to remove fractional results.
else if (isBinary(node, PLUS) || isBinary(node, MINUS)) {
auto left = node[2];
auto right = node[3];
- if (isOrZero(left) && isOrZero(right)) {
+ if (isOrZero(left) && isOrZero(right) && !isBinary(left[2], DIV) &&
+ !isBinary(right[2], DIV)) {
auto op = node[1]->getIString();
// Add a coercion on top.
node[1]->setString(OR);