summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h12
-rw-r--r--src/ast/properties.h60
-rw-r--r--src/passes/OptimizeInstructions.cpp10
-rw-r--r--test/emcc_O2_hello_world.fromasm42
-rw-r--r--test/emcc_O2_hello_world.fromasm.imprecise42
-rw-r--r--test/emcc_hello_world.fromasm61
-rw-r--r--test/emcc_hello_world.fromasm.imprecise61
-rw-r--r--test/memorygrowth.fromasm42
-rw-r--r--test/memorygrowth.fromasm.imprecise42
-rw-r--r--test/passes/optimize-instructions.txt50
-rw-r--r--test/passes/optimize-instructions.wast12
-rw-r--r--test/unit.asm.js57
-rw-r--r--test/unit.fromasm20
-rw-r--r--test/unit.fromasm.imprecise20
-rw-r--r--test/unit.fromasm.imprecise.no-opts20
-rw-r--r--test/unit.fromasm.no-opts20
-rw-r--r--test/wasm-only.fromasm2
17 files changed, 369 insertions, 204 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 5bdb2a9bf..377b6b20b 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -954,9 +954,15 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
void visitCallIndirect(CallIndirect* curr) {
// we already call into target = something + offset, where offset is a callImport with the name of the table. replace that with the table offset
auto add = curr->target->cast<Binary>();
- auto offset = add->right->cast<CallImport>();
- auto tableName = offset->target;
- add->right = parent->builder.makeConst(Literal((int32_t)parent->functionTableStarts[tableName]));
+ if (add->right->is<CallImport>()) {
+ auto offset = add->right->cast<CallImport>();
+ auto tableName = offset->target;
+ add->right = parent->builder.makeConst(Literal((int32_t)parent->functionTableStarts[tableName]));
+ } else {
+ auto offset = add->left->cast<CallImport>();
+ auto tableName = offset->target;
+ add->left = parent->builder.makeConst(Literal((int32_t)parent->functionTableStarts[tableName]));
+ }
}
};
diff --git a/src/ast/properties.h b/src/ast/properties.h
new file mode 100644
index 000000000..9834c73d0
--- /dev/null
+++ b/src/ast/properties.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef wasm_ast_properties_h
+#define wasm_ast_properties_h
+
+#include "wasm.h"
+
+namespace wasm {
+
+struct Properties {
+ static bool emitsBoolean(Expression* curr) {
+ if (auto* unary = curr->dynCast<Unary>()) {
+ return unary->isRelational();
+ } else if (auto* binary = curr->dynCast<Binary>()) {
+ return binary->isRelational();
+ }
+ return false;
+ }
+
+ static bool isSymmetric(Binary* binary) {
+ switch (binary->op) {
+ case AddInt32:
+ case MulInt32:
+ case AndInt32:
+ case OrInt32:
+ case XorInt32:
+ case EqInt32:
+ case NeInt32:
+
+ case AddInt64:
+ case MulInt64:
+ case AndInt64:
+ case OrInt64:
+ case XorInt64:
+ case EqInt64:
+ case NeInt64: return true;
+
+ default: return false;
+ }
+ }
+};
+
+} // wasm
+
+#endif // wams_ast_properties_h
+
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 7f1483371..a5c665458 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -25,6 +25,7 @@
#include <wasm-s-parser.h>
#include <support/threads.h>
#include <ast_utils.h>
+#include <ast/properties.h>
namespace wasm {
@@ -197,6 +198,12 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
// Optimizations that don't yet fit in the pattern DSL, but could be eventually maybe
Expression* handOptimize(Expression* curr) {
if (auto* binary = curr->dynCast<Binary>()) {
+ if (Properties::isSymmetric(binary)) {
+ // canonicalize a const to the second position
+ if (binary->left->is<Const>() && !binary->right->is<Const>()) {
+ std::swap(binary->left, binary->right);
+ }
+ }
// pattern match a load of 8 bits and a sign extend using a shl of 24 then shr_s of 24 as well, etc.
if (binary->op == BinaryOp::ShrSInt32 && binary->right->is<Const>()) {
auto shifts = binary->right->cast<Const>()->value.geti32();
@@ -238,6 +245,9 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
load->signed_ = false;
return load;
}
+ } else if (mask == 1 && Properties::emitsBoolean(binary->left)) {
+ // (bool) & 1 does not need the outer mask
+ return binary->left;
}
}
}
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index 1bfe482a1..a05612430 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -187,7 +187,6 @@
(i32.add
(tee_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $10
@@ -206,6 +205,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -368,7 +368,6 @@
(i32.add
(tee_local $11
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $10
@@ -448,6 +447,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -568,7 +568,6 @@
)
(set_local $11
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $19
@@ -581,6 +580,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -1068,7 +1068,6 @@
(i32.load
(tee_local $1
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $7
(i32.load offset=28
@@ -1077,6 +1076,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -1288,7 +1288,6 @@
)
(set_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $7
@@ -1301,6 +1300,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -2186,7 +2186,6 @@
(i32.load
(tee_local $11
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -2195,6 +2194,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -2376,7 +2376,6 @@
(block
(set_local $11
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $8)
@@ -2384,6 +2383,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -2466,7 +2466,6 @@
)
(set_local $8
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $10
(if i32
@@ -2567,6 +2566,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -4246,7 +4246,6 @@
(i32.load
(tee_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $21
(i32.load offset=28
@@ -4255,6 +4254,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -4412,7 +4412,6 @@
)
(tee_local $23
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $8)
@@ -4420,6 +4419,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -4572,7 +4572,6 @@
(block
(set_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $8)
@@ -4580,6 +4579,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(block $do-once59
@@ -4667,7 +4667,6 @@
)
(set_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(block $do-once61 i32
@@ -4774,6 +4773,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -5318,7 +5318,6 @@
(block
(set_local $18
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $4)
@@ -5326,6 +5325,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -5408,7 +5408,6 @@
)
(set_local $4
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(if i32
@@ -5509,6 +5508,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -5797,7 +5797,6 @@
(i32.store offset=12
(tee_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $2)
@@ -5805,6 +5804,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(get_local $0)
@@ -6159,7 +6159,6 @@
)
(tee_local $4
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $7)
@@ -6167,6 +6166,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -6464,7 +6464,6 @@
(i32.load
(tee_local $7
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $0
(i32.load offset=28
@@ -6473,6 +6472,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -7012,7 +7012,6 @@
(i32.load
(tee_local $5
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $9
(i32.load offset=28
@@ -7021,6 +7020,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -7180,7 +7180,6 @@
)
(tee_local $7
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $14)
@@ -7188,6 +7187,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -7335,7 +7335,6 @@
(block
(set_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $3)
@@ -7343,6 +7342,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -7425,7 +7425,6 @@
)
(set_local $5
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(if i32
@@ -7526,6 +7525,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise
index b351dbcc9..2e956e148 100644
--- a/test/emcc_O2_hello_world.fromasm.imprecise
+++ b/test/emcc_O2_hello_world.fromasm.imprecise
@@ -185,7 +185,6 @@
(i32.add
(tee_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $10
@@ -204,6 +203,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -366,7 +366,6 @@
(i32.add
(tee_local $11
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $10
@@ -446,6 +445,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -566,7 +566,6 @@
)
(set_local $11
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $19
@@ -579,6 +578,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -1066,7 +1066,6 @@
(i32.load
(tee_local $1
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $7
(i32.load offset=28
@@ -1075,6 +1074,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -1286,7 +1286,6 @@
)
(set_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $7
@@ -1299,6 +1298,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -2184,7 +2184,6 @@
(i32.load
(tee_local $11
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -2193,6 +2192,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -2374,7 +2374,6 @@
(block
(set_local $11
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $8)
@@ -2382,6 +2381,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -2464,7 +2464,6 @@
)
(set_local $8
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $10
(if i32
@@ -2565,6 +2564,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -4244,7 +4244,6 @@
(i32.load
(tee_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $21
(i32.load offset=28
@@ -4253,6 +4252,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -4410,7 +4410,6 @@
)
(tee_local $23
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $8)
@@ -4418,6 +4417,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -4570,7 +4570,6 @@
(block
(set_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $8)
@@ -4578,6 +4577,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(block $do-once59
@@ -4665,7 +4665,6 @@
)
(set_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(block $do-once61 i32
@@ -4772,6 +4771,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -5316,7 +5316,6 @@
(block
(set_local $18
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $4)
@@ -5324,6 +5323,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -5406,7 +5406,6 @@
)
(set_local $4
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(if i32
@@ -5507,6 +5506,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -5795,7 +5795,6 @@
(i32.store offset=12
(tee_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $2)
@@ -5803,6 +5802,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(get_local $0)
@@ -6157,7 +6157,6 @@
)
(tee_local $4
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $7)
@@ -6165,6 +6164,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -6462,7 +6462,6 @@
(i32.load
(tee_local $7
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $0
(i32.load offset=28
@@ -6471,6 +6470,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -7010,7 +7010,6 @@
(i32.load
(tee_local $5
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $9
(i32.load offset=28
@@ -7019,6 +7018,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -7178,7 +7178,6 @@
)
(tee_local $7
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $14)
@@ -7186,6 +7185,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -7333,7 +7333,6 @@
(block
(set_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $3)
@@ -7341,6 +7340,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -7423,7 +7423,6 @@
)
(set_local $5
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(if i32
@@ -7524,6 +7523,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 9119f1246..197810a43 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -3385,11 +3385,11 @@
(i32.load8_s
(i32.add
(i32.add
- (i32.const 3611)
(i32.mul
(get_local $10)
(i32.const 58)
)
+ (i32.const 3611)
)
(get_local $11)
)
@@ -5849,17 +5849,14 @@
)
)
(set_local $29
- (i32.and
- (i32.ne
- (tee_local $31
- (i32.or
- (get_local $5)
- (get_local $17)
- )
+ (i32.ne
+ (tee_local $31
+ (i32.or
+ (get_local $5)
+ (get_local $17)
)
- (i32.const 0)
)
- (i32.const 1)
+ (i32.const 0)
)
)
(set_local $19
@@ -6777,11 +6774,11 @@
)
(set_local $10
(i32.add
- (i32.const 4091)
(i32.shr_s
(get_local $17)
(i32.const 4)
)
+ (i32.const 4091)
)
)
(br $jumpthreading$inner$7)
@@ -8127,7 +8124,6 @@
(i32.add
(tee_local $3
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $4
@@ -8146,6 +8142,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -8308,7 +8305,6 @@
(i32.add
(tee_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $5
@@ -8388,6 +8384,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -8508,7 +8505,6 @@
)
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $0
@@ -8521,6 +8517,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -8999,7 +8996,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -9008,6 +9004,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -9219,7 +9216,6 @@
)
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $0
@@ -9232,6 +9228,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -10074,7 +10071,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -10083,6 +10079,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -10295,7 +10292,6 @@
(block
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $0)
@@ -10303,6 +10299,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -10385,7 +10382,6 @@
)
(set_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(if i32
@@ -10486,6 +10482,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -11821,7 +11818,6 @@
)
(tee_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $1)
@@ -11829,6 +11825,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -12109,7 +12106,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -12118,6 +12114,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -12312,7 +12309,6 @@
(block
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $0)
@@ -12320,6 +12316,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(block $do-once63
@@ -12407,7 +12404,6 @@
)
(set_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(block $do-once65 i32
@@ -12514,6 +12510,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -13009,7 +13006,6 @@
(block
(set_local $3
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $1)
@@ -13017,6 +13013,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -13099,7 +13096,6 @@
)
(set_local $3
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $4
(if i32
@@ -13200,6 +13196,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -13467,7 +13464,6 @@
(i32.store offset=12
(tee_local $4
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $3)
@@ -13475,6 +13471,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(get_local $4)
@@ -13824,7 +13821,6 @@
)
(tee_local $3
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $5)
@@ -13832,6 +13828,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -14116,7 +14113,6 @@
(i32.load
(tee_local $4
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $5
(i32.load offset=28
@@ -14125,6 +14121,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -14488,7 +14485,6 @@
)
(tee_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $3)
@@ -14496,6 +14492,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -14775,7 +14772,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(i32.load offset=28
@@ -14784,6 +14780,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -14978,7 +14975,6 @@
(block
(set_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $0)
@@ -14986,6 +14982,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -15068,7 +15065,6 @@
)
(set_local $4
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $5
(if i32
@@ -15169,6 +15165,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 040286385..ad1235d36 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -3378,11 +3378,11 @@
(i32.load8_s
(i32.add
(i32.add
- (i32.const 3611)
(i32.mul
(get_local $10)
(i32.const 58)
)
+ (i32.const 3611)
)
(get_local $11)
)
@@ -5842,17 +5842,14 @@
)
)
(set_local $29
- (i32.and
- (i32.ne
- (tee_local $31
- (i32.or
- (get_local $5)
- (get_local $17)
- )
+ (i32.ne
+ (tee_local $31
+ (i32.or
+ (get_local $5)
+ (get_local $17)
)
- (i32.const 0)
)
- (i32.const 1)
+ (i32.const 0)
)
)
(set_local $19
@@ -6770,11 +6767,11 @@
)
(set_local $10
(i32.add
- (i32.const 4091)
(i32.shr_s
(get_local $17)
(i32.const 4)
)
+ (i32.const 4091)
)
)
(br $jumpthreading$inner$7)
@@ -8120,7 +8117,6 @@
(i32.add
(tee_local $3
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $4
@@ -8139,6 +8135,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -8301,7 +8298,6 @@
(i32.add
(tee_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $5
@@ -8381,6 +8377,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(i32.const 8)
@@ -8501,7 +8498,6 @@
)
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $0
@@ -8514,6 +8510,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -8992,7 +8989,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -9001,6 +8997,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -9212,7 +9209,6 @@
)
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(tee_local $0
@@ -9225,6 +9221,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -10067,7 +10064,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -10076,6 +10072,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -10288,7 +10285,6 @@
(block
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $0)
@@ -10296,6 +10292,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -10378,7 +10375,6 @@
)
(set_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(if i32
@@ -10479,6 +10475,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -11814,7 +11811,6 @@
)
(tee_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $1)
@@ -11822,6 +11818,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -12102,7 +12099,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -12111,6 +12107,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -12305,7 +12302,6 @@
(block
(set_local $2
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $0)
@@ -12313,6 +12309,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(block $do-once63
@@ -12400,7 +12397,6 @@
)
(set_local $2
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(block $do-once65 i32
@@ -12507,6 +12503,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -13002,7 +12999,6 @@
(block
(set_local $3
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $1)
@@ -13010,6 +13006,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -13092,7 +13089,6 @@
)
(set_local $3
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $4
(if i32
@@ -13193,6 +13189,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
@@ -13460,7 +13457,6 @@
(i32.store offset=12
(tee_local $4
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $3)
@@ -13468,6 +13464,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(get_local $4)
@@ -13817,7 +13814,6 @@
)
(tee_local $3
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $5)
@@ -13825,6 +13821,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -14109,7 +14106,6 @@
(i32.load
(tee_local $4
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $5
(i32.load offset=28
@@ -14118,6 +14114,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -14481,7 +14478,6 @@
)
(tee_local $0
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $3)
@@ -14489,6 +14485,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
)
@@ -14768,7 +14765,6 @@
(i32.load
(tee_local $0
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $3
(i32.load offset=28
@@ -14777,6 +14773,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
)
@@ -14971,7 +14968,6 @@
(block
(set_local $1
(i32.add
- (i32.const 216)
(i32.shl
(i32.shl
(get_local $0)
@@ -14979,6 +14975,7 @@
)
(i32.const 2)
)
+ (i32.const 216)
)
)
(if
@@ -15061,7 +15058,6 @@
)
(set_local $4
(i32.add
- (i32.const 480)
(i32.shl
(tee_local $5
(if i32
@@ -15162,6 +15158,7 @@
)
(i32.const 2)
)
+ (i32.const 480)
)
)
(i32.store offset=28
diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm
index 6f160c6bc..193125930 100644
--- a/test/memorygrowth.fromasm
+++ b/test/memorygrowth.fromasm
@@ -200,7 +200,6 @@
(i32.add
(tee_local $8
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $0
@@ -219,6 +218,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(i32.const 8)
@@ -384,7 +384,6 @@
(i32.add
(tee_local $1
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $15
@@ -464,6 +463,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(i32.const 8)
@@ -584,7 +584,6 @@
)
(set_local $5
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $13
@@ -597,6 +596,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -1089,7 +1089,6 @@
(i32.load
(tee_local $1
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $7
(i32.load offset=28
@@ -1098,6 +1097,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -1309,7 +1309,6 @@
)
(set_local $1
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $7
@@ -1322,6 +1321,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -2220,7 +2220,6 @@
(i32.load
(tee_local $9
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -2229,6 +2228,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -2441,7 +2441,6 @@
(block
(set_local $4
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $9)
@@ -2449,6 +2448,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -2531,7 +2531,6 @@
)
(set_local $16
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $15
(if i32
@@ -2632,6 +2631,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
@@ -4130,7 +4130,6 @@
)
(tee_local $19
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $0)
@@ -4138,6 +4137,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
)
@@ -4429,7 +4429,6 @@
(i32.load
(tee_local $21
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $0
(i32.load offset=28
@@ -4438,6 +4437,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -4632,7 +4632,6 @@
(block
(set_local $3
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $0)
@@ -4640,6 +4639,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(block $do-once59
@@ -4727,7 +4727,6 @@
)
(set_local $0
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $5
(block $do-once61 i32
@@ -4834,6 +4833,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
@@ -5359,7 +5359,6 @@
(block
(set_local $12
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $1)
@@ -5367,6 +5366,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -5449,7 +5449,6 @@
)
(set_local $0
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $3
(if i32
@@ -5550,6 +5549,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
@@ -5838,7 +5838,6 @@
(i32.store offset=12
(tee_local $12
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $1)
@@ -5846,6 +5845,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(get_local $12)
@@ -6206,7 +6206,6 @@
)
(tee_local $4
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $3)
@@ -6214,6 +6213,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
)
@@ -6511,7 +6511,6 @@
(i32.load
(tee_local $3
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $0
(i32.load offset=28
@@ -6520,6 +6519,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -6886,7 +6886,6 @@
)
(tee_local $4
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $14)
@@ -6894,6 +6893,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
)
@@ -7179,7 +7179,6 @@
(i32.load
(tee_local $7
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $3
(i32.load offset=28
@@ -7188,6 +7187,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -7382,7 +7382,6 @@
(block
(set_local $1
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $6)
@@ -7390,6 +7389,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -7472,7 +7472,6 @@
)
(set_local $5
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $6
(if i32
@@ -7573,6 +7572,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise
index 89072fdd9..7a2dd39a7 100644
--- a/test/memorygrowth.fromasm.imprecise
+++ b/test/memorygrowth.fromasm.imprecise
@@ -198,7 +198,6 @@
(i32.add
(tee_local $8
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $0
@@ -217,6 +216,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(i32.const 8)
@@ -382,7 +382,6 @@
(i32.add
(tee_local $1
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $15
@@ -462,6 +461,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(i32.const 8)
@@ -582,7 +582,6 @@
)
(set_local $5
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $13
@@ -595,6 +594,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -1087,7 +1087,6 @@
(i32.load
(tee_local $1
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $7
(i32.load offset=28
@@ -1096,6 +1095,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -1307,7 +1307,6 @@
)
(set_local $1
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(tee_local $7
@@ -1320,6 +1319,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -2218,7 +2218,6 @@
(i32.load
(tee_local $9
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $1
(i32.load offset=28
@@ -2227,6 +2226,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -2439,7 +2439,6 @@
(block
(set_local $4
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $9)
@@ -2447,6 +2446,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -2529,7 +2529,6 @@
)
(set_local $16
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $15
(if i32
@@ -2630,6 +2629,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
@@ -4128,7 +4128,6 @@
)
(tee_local $19
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $0)
@@ -4136,6 +4135,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
)
@@ -4427,7 +4427,6 @@
(i32.load
(tee_local $21
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $0
(i32.load offset=28
@@ -4436,6 +4435,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -4630,7 +4630,6 @@
(block
(set_local $3
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $0)
@@ -4638,6 +4637,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(block $do-once59
@@ -4725,7 +4725,6 @@
)
(set_local $0
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $5
(block $do-once61 i32
@@ -4832,6 +4831,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
@@ -5357,7 +5357,6 @@
(block
(set_local $12
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $1)
@@ -5365,6 +5364,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -5447,7 +5447,6 @@
)
(set_local $0
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $3
(if i32
@@ -5548,6 +5547,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
@@ -5836,7 +5836,6 @@
(i32.store offset=12
(tee_local $12
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $1)
@@ -5844,6 +5843,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(get_local $12)
@@ -6204,7 +6204,6 @@
)
(tee_local $4
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $3)
@@ -6212,6 +6211,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
)
@@ -6509,7 +6509,6 @@
(i32.load
(tee_local $3
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $0
(i32.load offset=28
@@ -6518,6 +6517,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -6884,7 +6884,6 @@
)
(tee_local $4
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $14)
@@ -6892,6 +6891,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
)
@@ -7177,7 +7177,6 @@
(i32.load
(tee_local $7
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $3
(i32.load offset=28
@@ -7186,6 +7185,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
)
@@ -7380,7 +7380,6 @@
(block
(set_local $1
(i32.add
- (i32.const 1248)
(i32.shl
(i32.shl
(get_local $6)
@@ -7388,6 +7387,7 @@
)
(i32.const 2)
)
+ (i32.const 1248)
)
)
(if
@@ -7470,7 +7470,6 @@
)
(set_local $5
(i32.add
- (i32.const 1512)
(i32.shl
(tee_local $6
(if i32
@@ -7571,6 +7570,7 @@
)
(i32.const 2)
)
+ (i32.const 1512)
)
)
(i32.store offset=28
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index ca5898e73..c93c7d1fa 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -313,4 +313,54 @@
)
)
)
+ (func $and-pos1 (type $1)
+ (drop
+ (i32.eqz
+ (i32.const 1000)
+ )
+ )
+ (drop
+ (i32.eqz
+ (i32.const 1000)
+ )
+ )
+ (drop
+ (i32.and
+ (i32.const 100)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.lt_s
+ (i32.const 2000)
+ (i32.const 3000)
+ )
+ )
+ )
+ (func $canonicalize-binary (type $1)
+ (drop
+ (i32.and
+ (unreachable)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.and
+ (unreachable)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.div_s
+ (unreachable)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.div_s
+ (i32.const 1)
+ (unreachable)
+ )
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index e6d18240d..99e77ea9e 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -275,4 +275,16 @@
(drop (i32.and (i32.const 100) (i32.const -1)))
(drop (i32.and (i32.const 100) (i32.const 1)))
)
+ (func $and-pos1
+ (drop (i32.and (i32.eqz (i32.const 1000)) (i32.const 1)))
+ (drop (i32.and (i32.const 1) (i32.eqz (i32.const 1000))))
+ (drop (i32.and (i32.const 100) (i32.const 1)))
+ (drop (i32.and (i32.lt_s (i32.const 2000) (i32.const 3000)) (i32.const 1)))
+ )
+ (func $canonicalize-binary
+ (drop (i32.and (unreachable) (i32.const 1))) ;; ok to reorder
+ (drop (i32.and (i32.const 1) (unreachable)))
+ (drop (i32.div_s (unreachable) (i32.const 1))) ;; not ok
+ (drop (i32.div_s (i32.const 1) (unreachable)))
+ )
)
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 949d68dcb..6ccf6c489 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -37,28 +37,28 @@ function asm(global, env, buffer) {
function importedDoubles() {
var temp = 0.0;
temp = t + u + (-u) + (-t);
- if (Int > 0) return -3.4;
+ if ((Int | 0) > 0) return -3.4;
if (Double > 0.0) return 5.6;
return 1.2;
}
function doubleCompares(x, y) {
x = +x;
y = +y;
- var t = +0;
+ var t = 0.0;
var Int = 0.0, Double = 0; // confusing with globals
if (x > 0.0) return 1.2;
if (Int > 0.0) return -3.4;
- if (Double > 0) return 5.6;
+ if ((Double|0) > 0) return 5.6;
if (x < y) return +x;
return +y;
}
function intOps() {
var x = 0;
- return !x;
+ return (!x) | 0;
}
function hexLiterals() {
var i = 0;
- i = 0x0 + 0x12ABCdef + 0xFEDcba90;
+ i = 0x0 + 0x12ABCdef + 0xFEDcba90 | 0;
}
function conversions() {
var i = 0, d = 0.0, f = Math_fround(0);
@@ -100,7 +100,7 @@ function asm(global, env, buffer) {
}
L1 : while (1) {
- L3 : while (1) switch (x) {
+ L3 : while (1) switch (x | 0) {
case -1:
{
break L1;
@@ -160,7 +160,7 @@ function asm(global, env, buffer) {
}
function neg() {
var x = Math_fround(0);
- x = -x;
+ x = Math_fround(-x);
FUNCTION_TABLE_c[1 & 7](x);
}
function cneg(x) {
@@ -178,7 +178,7 @@ function asm(global, env, buffer) {
return i | 0;
}
function cneg_nosemicolon() {
- FUNCTION_TABLE_c[1 & 7](1) // no semicolon
+ FUNCTION_TABLE_vi[1 & 7](1) // no semicolon
}
function forLoop() {
var i = 0;
@@ -198,14 +198,14 @@ function asm(global, env, buffer) {
abort(55);
abort();
abort(12.34);
- abort(Math_fround(56.78));
+ abort(+Math_fround(56.78));
}
function continues() {
while (1) {
print(1);
do {
print(5);
- if (return_int()) continue;
+ if (return_int() | 0) continue;
} while (0);
print(2);
}
@@ -221,7 +221,7 @@ function asm(global, env, buffer) {
}
function recursiveBlockMerging(x) {
x = x | 0;
- lb((1, x) + (2, 3) + (((4, 5), 6), 7) + (8, (9, (10, (11, 12))))) | 0;
+ lb((1, x) + (2, 3) + (((4, 5), 6), 7) + (8, (9, (10, (11, 12)))) | 0) | 0;
x = (lb(1) | 0, x) + (lb(2) | 0, lb(3) | 0) + (((lb(4) | 0, lb(5) | 0), lb(6) | 0), lb(7) | 0) + (lb(8) | 0, (lb(9) | 0, (lb(10) | 0, (lb(11) | 0, lb(12) | 0)))) | 0;
return x | 0;
}
@@ -276,7 +276,7 @@ function asm(global, env, buffer) {
function dropCall() {
if (return_int() | 0) {
- phi(); // drop this
+ phi() | 0; // drop this
setTempRet0(10); // this too
zeroInit(setTempRet0(10) | 0);
}
@@ -327,7 +327,7 @@ function asm(global, env, buffer) {
}
function conditionalTypeFun() {
- var x = 0, y = +0;
+ var x = 0, y = 0.0;
x = return_int() | 0 ? abort(5) | 0 : 2;
y = return_int() | 0 ? +abort(7) : 4.5;
}
@@ -344,13 +344,15 @@ function asm(global, env, buffer) {
loadSigned(HEAPU16[x >> 1] << 24 >> 16);
}
- function z() {
+ function z(x) {
+ x = Math_fround(x);
}
function w() {
+ return 0.0;
}
function globalOpts() {
- var x = 0, y = +0;
+ var x = 0, y = 0.0;
x = Int;
y = Double;
HEAP8[13] = HEAP32[3]; // access memory, should not confuse the global writes
@@ -384,7 +386,7 @@ function asm(global, env, buffer) {
}
}
inc = loopvar + 1 | 0;
- if (inc == y) {
+ if ((inc|0) == (y|0)) {
loopvar = inc;
} else {
break;
@@ -430,7 +432,7 @@ function asm(global, env, buffer) {
h(-1);
// from loop
while (1) {
- x = x + 1;
+ x = x + 1 | 0;
if (x) {
h(2);
label = 2;
@@ -444,7 +446,7 @@ function asm(global, env, buffer) {
// if-else afterward
if (x) {
h(4);
- if (x == 3) {
+ if ((x|0) == 3) {
label = 3;
} else {
label = 4;
@@ -459,7 +461,7 @@ function asm(global, env, buffer) {
// two ifs afterward
if (x) {
h(7);
- if (x == 5) {
+ if ((x|0) == 5) {
label = 5;
} else {
label = 6;
@@ -467,7 +469,7 @@ function asm(global, env, buffer) {
}
if ((label|0) == 5) {
h(8);
- if (x == 6) {
+ if ((x|0) == 6) {
label = 6;
}
}
@@ -490,7 +492,7 @@ function asm(global, env, buffer) {
// labeled if after normal if
if (x) {
h(12);
- if (x == 8) {
+ if ((x|0) == 8) {
label = 8;
} else {
label = 9;
@@ -511,7 +513,7 @@ function asm(global, env, buffer) {
// labeled if after a first if
// do-enclosed if after (?)
// test multiple labels, some should be ignored initially by JumpUpdater
- return x;
+ return x | 0;
}
function relooperJumpThreading__ZN4game14preloadweaponsEv() {
@@ -601,9 +603,16 @@ function asm(global, env, buffer) {
return;
}
- var FUNCTION_TABLE_a = [ z, big_negative, z, z ];
+ function v() {
+ }
+ function vi(x) {
+ x = x | 0;
+ }
+
+ var FUNCTION_TABLE_a = [ v, big_negative, v, v ];
var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ];
- var FUNCTION_TABLE_c = [ z, cneg ];
+ var FUNCTION_TABLE_c = [ z, cneg, z, z, z, z, z, z ];
+ var FUNCTION_TABLE_vi = [ vi, vi, vi, vi, vi, vi, vi, vi ];
return { big_negative: big_negative, pick: forgetMe, pick: exportMe, doubleCompares: doubleCompares, intOps: intOps, conversions: conversions, switcher: switcher, frem: frem, big_uint_div_u: big_uint_div_u, fr: fr, negZero: negZero, neg: neg, smallCompare: smallCompare, cneg_nosemicolon: cneg_nosemicolon, forLoop: forLoop, ceiling_32_64: ceiling_32_64, aborts: aborts, continues: continues, bitcasts: bitcasts, recursiveBlockMerging: recursiveBlockMerging, lb: lb, zeroInit: zeroInit, phi: phi, smallIf: smallIf, dropCall: dropCall, useSetGlobal: useSetGlobal, usesSetGlobal2: usesSetGlobal2, breakThroughMany: breakThroughMany, ifChainEmpty: ifChainEmpty, heap8NoShift: heap8NoShift, conditionalTypeFun: conditionalTypeFun, loadSigned: loadSigned, globalOpts: globalOpts, dropCallImport: dropCallImport, loophi: loophi, loophi2: loophi2, relooperJumpThreading: relooperJumpThreading, relooperJumpThreading__ZN4game14preloadweaponsEv: relooperJumpThreading__ZN4game14preloadweaponsEv, __Z12multi_varargiz: __Z12multi_varargiz, jumpThreadDrop: jumpThreadDrop, dropIgnoredImportInIf: dropIgnoredImportInIf, dropIgnoredImportsInIf: dropIgnoredImportsInIf };
}
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 905d12b86..a6dac1e63 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -21,10 +21,10 @@
(import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64)))
(import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 10 10 anyfunc))
+ (import "env" "table" (table 24 24 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg)
+ (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi)
(data (get_global $memoryBase) "unit.asm.js")
(global $t (mut f64) (get_global $t$asm2wasm$import))
(global $u (mut f64) (get_global $u$asm2wasm$import))
@@ -272,8 +272,8 @@
(get_local $0)
)
(i32.add
- (i32.const 1)
(i32.const 8)
+ (i32.const 1)
)
)
)
@@ -281,8 +281,8 @@
(call_indirect $FUNCSIG$vf
(get_local $0)
(i32.add
- (i32.const 1)
(i32.const 8)
+ (i32.const 1)
)
)
)
@@ -319,8 +319,8 @@
(call_indirect $FUNCSIG$vi
(i32.const 1)
(i32.add
+ (i32.const 16)
(i32.const 1)
- (i32.const 8)
)
)
)
@@ -378,9 +378,7 @@
)
(drop
(call $abort
- (f64.promote/f32
- (f32.const 56.779998779296875)
- )
+ (f64.const 56.779998779296875)
)
)
)
@@ -719,6 +717,9 @@
)
)
)
+ (func $w (result f64)
+ (f64.const 0)
+ )
(func $globalOpts
(local $0 i32)
(i32.store8
@@ -1072,4 +1073,7 @@
)
)
)
+ (func $vi (param $0 i32)
+ (nop)
+ )
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 0760055bc..bb1147d16 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -17,10 +17,10 @@
(import "env" "return_int" (func $return_int (result i32)))
(import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 10 10 anyfunc))
+ (import "env" "table" (table 24 24 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg)
+ (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $w $w $importedDoubles $w $fr $cneg $fr $fr $fr $fr $fr $fr $vi $vi $vi $vi $vi $vi $vi $vi)
(global $t (mut f64) (get_global $t$asm2wasm$import))
(global $u (mut f64) (get_global $u$asm2wasm$import))
(global $Int (mut i32) (i32.const 0))
@@ -256,8 +256,8 @@
(get_local $0)
)
(i32.add
- (i32.const 1)
(i32.const 8)
+ (i32.const 1)
)
)
)
@@ -265,8 +265,8 @@
(call_indirect $FUNCSIG$vf
(get_local $0)
(i32.add
- (i32.const 1)
(i32.const 8)
+ (i32.const 1)
)
)
)
@@ -303,8 +303,8 @@
(call_indirect $FUNCSIG$vi
(i32.const 1)
(i32.add
+ (i32.const 16)
(i32.const 1)
- (i32.const 8)
)
)
)
@@ -362,9 +362,7 @@
)
(drop
(call $abort
- (f64.promote/f32
- (f32.const 56.779998779296875)
- )
+ (f64.const 56.779998779296875)
)
)
)
@@ -703,6 +701,9 @@
)
)
)
+ (func $w (result f64)
+ (f64.const 0)
+ )
(func $globalOpts
(local $0 i32)
(i32.store8
@@ -1056,4 +1057,7 @@
)
)
)
+ (func $vi (param $0 i32)
+ (nop)
+ )
)
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index d57861df3..f372b2d57 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -17,10 +17,10 @@
(import "env" "return_int" (func $return_int (result i32)))
(import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 10 10 anyfunc))
+ (import "env" "table" (table 24 24 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg)
+ (elem (i32.const 0) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi)
(global $t (mut f64) (get_global $t$asm2wasm$import))
(global $u (mut f64) (get_global $u$asm2wasm$import))
(global $Int (mut i32) (i32.const 0))
@@ -526,7 +526,7 @@
(i32.const 1)
(i32.const 7)
)
- (i32.const 8)
+ (i32.const 16)
)
)
)
@@ -1130,11 +1130,13 @@
)
)
)
- (func $z
+ (func $z (param $x f32)
(nop)
)
- (func $w
- (nop)
+ (func $w (result f64)
+ (return
+ (f64.const 0)
+ )
)
(func $globalOpts
(local $x i32)
@@ -1694,4 +1696,10 @@
)
(return)
)
+ (func $v
+ (nop)
+ )
+ (func $vi (param $x i32)
+ (nop)
+ )
)
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index ef985ce07..0b90cb3b8 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -21,10 +21,10 @@
(import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64)))
(import "asm2wasm" "i32u-div" (func $i32u-div (param i32 i32) (result i32)))
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table 10 10 anyfunc))
+ (import "env" "table" (table 24 24 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg)
+ (elem (i32.const 0) $v $big_negative $v $v $w $w $importedDoubles $w $z $cneg $z $z $z $z $z $z $vi $vi $vi $vi $vi $vi $vi $vi)
(global $t (mut f64) (get_global $t$asm2wasm$import))
(global $u (mut f64) (get_global $u$asm2wasm$import))
(global $Int (mut i32) (i32.const 0))
@@ -532,7 +532,7 @@
(i32.const 1)
(i32.const 7)
)
- (i32.const 8)
+ (i32.const 16)
)
)
)
@@ -1136,11 +1136,13 @@
)
)
)
- (func $z
+ (func $z (param $x f32)
(nop)
)
- (func $w
- (nop)
+ (func $w (result f64)
+ (return
+ (f64.const 0)
+ )
)
(func $globalOpts
(local $x i32)
@@ -1700,4 +1702,10 @@
)
(return)
)
+ (func $v
+ (nop)
+ )
+ (func $vi (param $x i32)
+ (nop)
+ )
)
diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm
index cda8e711f..9fd95ed27 100644
--- a/test/wasm-only.fromasm
+++ b/test/wasm-only.fromasm
@@ -182,10 +182,10 @@
(i64.mul
(i64.sub
(i64.add
- (i64.const 100)
(tee_local $1
(i64.const 128849018897)
)
+ (i64.const 100)
)
(get_local $1)
)