summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/CMakeLists.txt1
-rw-r--r--src/passes/Precompute.cpp103
-rw-r--r--src/passes/pass.cpp2
-rw-r--r--src/wasm-builder.h1
-rw-r--r--src/wasm-interpreter.h38
-rw-r--r--src/wasm.cpp3
-rw-r--r--test/emcc_O2_hello_world.fromasm5
-rw-r--r--test/emcc_O2_hello_world.fromasm.imprecise5
-rw-r--r--test/emcc_hello_world.fromasm152
-rw-r--r--test/emcc_hello_world.fromasm.imprecise152
-rw-r--r--test/memorygrowth.fromasm5
-rw-r--r--test/memorygrowth.fromasm.imprecise5
-rw-r--r--test/min.fromasm4
-rw-r--r--test/min.fromasm.imprecise4
-rw-r--r--test/passes/precompute.txt16
-rw-r--r--test/passes/precompute.wast19
-rw-r--r--test/unit.fromasm23
-rw-r--r--test/unit.fromasm.imprecise23
18 files changed, 228 insertions, 333 deletions
diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt
index 9e69cbae2..2ccf5f040 100644
--- a/src/passes/CMakeLists.txt
+++ b/src/passes/CMakeLists.txt
@@ -11,6 +11,7 @@ SET(passes_SOURCES
NameList.cpp
OptimizeInstructions.cpp
PostEmscripten.cpp
+ Precompute.cpp
Print.cpp
RemoveImports.cpp
RemoveMemory.cpp
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
new file mode 100644
index 000000000..db6999cbd
--- /dev/null
+++ b/src/passes/Precompute.cpp
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+//
+// Removes dead, i.e. unreachable, code.
+//
+// We keep a record of when control flow is reachable. When it isn't, we
+// kill (turn into unreachable). We then fold away entire unreachable
+// expressions.
+//
+// When dead code causes an operation to not happen, like a store, a call
+// or an add, we replace with a block with a list of what does happen.
+// That isn't necessarily smaller, but blocks are friendlier to other
+// optimizations: blocks can be merged and eliminated, and they clearly
+// have no side effects.
+//
+
+#include <wasm.h>
+#include <pass.h>
+#include <wasm-builder.h>
+#include <wasm-interpreter.h>
+
+namespace wasm {
+
+// Execute an expression by itself. Errors if we hit anything we need anything not in the expression itself standalone.
+class StandaloneExpressionRunner : public ExpressionRunner<StandaloneExpressionRunner> {
+public:
+ struct NonstandaloneException {}; // TODO: use a flow with a special name, as this is likely very slow
+
+ Flow visitLoop(Loop* curr) {
+ // loops might be infinite, so must be careful
+ // but we can't tell if non-infinite, since we don't have state, so loops are just impossible to optimize for now
+ throw NonstandaloneException();
+ }
+
+ Flow visitCall(Call* curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitCallImport(CallImport* curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitCallIndirect(CallIndirect* curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitGetLocal(GetLocal *curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitSetLocal(SetLocal *curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitLoad(Load *curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitStore(Store *curr) {
+ throw NonstandaloneException();
+ }
+ Flow visitHost(Host *curr) {
+ throw NonstandaloneException();
+ }
+
+ void trap(const char* why) override {
+ throw NonstandaloneException();
+ }
+};
+
+struct Precompute : public WalkerPass<PostWalker<Precompute, UnifiedExpressionVisitor<Precompute>>> {
+ bool isFunctionParallel() override { return true; }
+
+ Pass* create() override { return new Precompute; }
+
+ void visitExpression(Expression* curr) {
+ if (curr->is<Const>()) return;
+ // try to evaluate this into a const
+ Flow flow;
+ try {
+ flow = StandaloneExpressionRunner().visit(curr);
+ } catch (StandaloneExpressionRunner::NonstandaloneException& e) {
+ return;
+ }
+ if (flow.breaking()) return; // TODO: can create a break as a replacement
+ if (isConcreteWasmType(flow.value.type)) {
+ replaceCurrent(Builder(*getModule()).makeConst(flow.value));
+ }
+ }
+};
+
+static RegisterPass<Precompute> registerPass("precompute", "computes compile-time evaluatable expressions");
+
+} // namespace wasm
+
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index babb4635b..c5315a044 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -63,6 +63,7 @@ void PassRunner::addDefaultOptimizationPasses() {
add("remove-unused-brs");
add("remove-unused-names");
add("optimize-instructions");
+ add("precompute");
add("simplify-locals");
add("vacuum"); // previous pass creates garbage
add("remove-unused-brs"); // simplify-locals opens opportunities for phi optimizations
@@ -80,6 +81,7 @@ void PassRunner::addDefaultFunctionOptimizationPasses() {
add("remove-unused-brs");
add("remove-unused-names");
add("optimize-instructions");
+ add("precompute");
add("simplify-locals");
add("vacuum"); // previous pass creates garbage
add("remove-unused-brs"); // simplify-locals opens opportunities for phi optimizations
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index ae8d5fa4c..2eb051251 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -134,6 +134,7 @@ public:
return ret;
}
Const* makeConst(Literal value) {
+ assert(isConcreteWasmType(value.type));
auto* ret = wasm.allocator.alloc<Const>();
ret->value = value;
ret->type = value.type;
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 55edbdfa0..f7e213b93 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -39,8 +39,7 @@ using namespace cashew;
// Utilities
-IString WASM("wasm"),
- RETURN_FLOW("*return:)*");
+extern Name WASM, RETURN_FLOW;
enum {
maxCallDepth = 250
@@ -492,41 +491,6 @@ public:
}
};
-// Execute an expression by itself. Errors if we hit anything we need anything not in the expression itself standalone.
-class StandaloneExpressionRunner : public ExpressionRunner<StandaloneExpressionRunner> {
-public:
- struct NonstandaloneException {};
-
- Flow visitCall(Call* curr) {
- throw NonstandaloneException();
- }
- Flow visitCallImport(CallImport* curr) {
- throw NonstandaloneException();
- }
- Flow visitCallIndirect(CallIndirect* curr) {
- throw NonstandaloneException();
- }
- Flow visitGetLocal(GetLocal *curr) {
- throw NonstandaloneException();
- }
- Flow visitSetLocal(SetLocal *curr) {
- throw NonstandaloneException();
- }
- Flow visitLoad(Load *curr) {
- throw NonstandaloneException();
- }
- Flow visitStore(Store *curr) {
- throw NonstandaloneException();
- }
- Flow visitHost(Host *curr) {
- throw NonstandaloneException();
- }
-
- void trap(const char* why) {
- throw NonstandaloneException();
- }
-};
-
//
// An instance of a WebAssembly module, which can execute it via AST interpretation.
//
diff --git a/src/wasm.cpp b/src/wasm.cpp
index 48a0f276a..dd06a8d14 100644
--- a/src/wasm.cpp
+++ b/src/wasm.cpp
@@ -20,6 +20,9 @@
namespace wasm {
+Name WASM("wasm"),
+ RETURN_FLOW("*return:)*");
+
struct TypeSeeker : public PostWalker<TypeSeeker, Visitor<TypeSeeker>> {
Expression* target; // look for this one
Name targetName;
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index acbeb2a0b..be4324f2c 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -9223,10 +9223,7 @@
(set_local $6
(i32.and
(get_local $4)
- (i32.xor
- (i32.const 3)
- (i32.const -1)
- )
+ (i32.const -4)
)
)
(if
diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise
index acbeb2a0b..be4324f2c 100644
--- a/test/emcc_O2_hello_world.fromasm.imprecise
+++ b/test/emcc_O2_hello_world.fromasm.imprecise
@@ -9223,10 +9223,7 @@
(set_local $6
(i32.and
(get_local $4)
- (i32.xor
- (i32.const 3)
- (i32.const -1)
- )
+ (i32.const -4)
)
)
(if
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 02e6d6002..d42874592 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -3744,19 +3744,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -4159,19 +4153,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -5312,10 +5300,7 @@
(get_local $1)
(i32.const 2146435072)
)
- (i32.lt_s
- (i32.const 0)
- (i32.const 0)
- )
+ (i32.const 0)
)
)
(block
@@ -7959,10 +7944,7 @@
(get_local $14)
(get_local $14)
)
- (f64.ne
- (f64.const 0)
- (f64.const 0)
- )
+ (i32.const 0)
)
)
)
@@ -9034,19 +9016,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9077,19 +9053,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9133,19 +9103,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9181,19 +9145,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
(i32.const -1)
@@ -9234,19 +9192,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9304,19 +9256,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9354,19 +9300,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9424,19 +9364,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9474,19 +9408,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
(i32.const -1)
@@ -9517,19 +9445,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
(i32.const -1)
@@ -15472,20 +15394,20 @@
)
(i32.store offset=4
(get_local $4)
- (i32.load offset=4
- (i32.const 624)
+ (i32.load
+ (i32.const 628)
)
)
(i32.store offset=8
(get_local $4)
- (i32.load offset=8
- (i32.const 624)
+ (i32.load
+ (i32.const 632)
)
)
(i32.store offset=12
(get_local $4)
- (i32.load offset=12
- (i32.const 624)
+ (i32.load
+ (i32.const 636)
)
)
(i32.store
@@ -18127,10 +18049,7 @@
(set_local $6
(i32.and
(get_local $4)
- (i32.xor
- (i32.const 3)
- (i32.const -1)
- )
+ (i32.const -4)
)
)
(if
@@ -20027,10 +19946,7 @@
(get_local $7)
(i32.const 1)
)
- (i32.shr_u
- (i32.const 0)
- (i32.const 31)
- )
+ (i32.const 0)
)
(i32.const -2)
)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index b7e3d5f59..8899b7965 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -3742,19 +3742,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -4157,19 +4151,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -5310,10 +5298,7 @@
(get_local $1)
(i32.const 2146435072)
)
- (i32.lt_s
- (i32.const 0)
- (i32.const 0)
- )
+ (i32.const 0)
)
)
(block
@@ -7957,10 +7942,7 @@
(get_local $14)
(get_local $14)
)
- (f64.ne
- (f64.const 0)
- (f64.const 0)
- )
+ (i32.const 0)
)
)
)
@@ -9032,19 +9014,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9075,19 +9051,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9131,19 +9101,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9179,19 +9143,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
(i32.const -1)
@@ -9232,19 +9190,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9302,19 +9254,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9352,19 +9298,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9422,19 +9362,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 4)
- )
+ (i32.const 4)
(i32.const 1)
)
(i32.const -1)
@@ -9472,19 +9406,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
(i32.const -1)
@@ -9515,19 +9443,13 @@
(get_local $2)
)
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
)
(i32.xor
(i32.sub
- (i32.add
- (i32.const 0)
- (i32.const 8)
- )
+ (i32.const 8)
(i32.const 1)
)
(i32.const -1)
@@ -15470,20 +15392,20 @@
)
(i32.store offset=4
(get_local $4)
- (i32.load offset=4
- (i32.const 624)
+ (i32.load
+ (i32.const 628)
)
)
(i32.store offset=8
(get_local $4)
- (i32.load offset=8
- (i32.const 624)
+ (i32.load
+ (i32.const 632)
)
)
(i32.store offset=12
(get_local $4)
- (i32.load offset=12
- (i32.const 624)
+ (i32.load
+ (i32.const 636)
)
)
(i32.store
@@ -18125,10 +18047,7 @@
(set_local $6
(i32.and
(get_local $4)
- (i32.xor
- (i32.const 3)
- (i32.const -1)
- )
+ (i32.const -4)
)
)
(if
@@ -20025,10 +19944,7 @@
(get_local $7)
(i32.const 1)
)
- (i32.shr_u
- (i32.const 0)
- (i32.const 31)
- )
+ (i32.const 0)
)
(i32.const -2)
)
diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm
index 3d3f9468b..9f2c4b2b8 100644
--- a/test/memorygrowth.fromasm
+++ b/test/memorygrowth.fromasm
@@ -9289,10 +9289,7 @@
(set_local $6
(i32.and
(get_local $4)
- (i32.xor
- (i32.const 3)
- (i32.const -1)
- )
+ (i32.const -4)
)
)
(if
diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise
index 3d3f9468b..9f2c4b2b8 100644
--- a/test/memorygrowth.fromasm.imprecise
+++ b/test/memorygrowth.fromasm.imprecise
@@ -9289,10 +9289,7 @@
(set_local $6
(i32.and
(get_local $4)
- (i32.xor
- (i32.const 3)
- (i32.const -1)
- )
+ (i32.const -4)
)
)
(if
diff --git a/test/min.fromasm b/test/min.fromasm
index 51750dd53..b5d826e4f 100644
--- a/test/min.fromasm
+++ b/test/min.fromasm
@@ -24,8 +24,6 @@
(nop)
)
(func $ctzzzz (result i32)
- (i32.ctz
- (i32.const 4660)
- )
+ (i32.const 2)
)
)
diff --git a/test/min.fromasm.imprecise b/test/min.fromasm.imprecise
index 51750dd53..b5d826e4f 100644
--- a/test/min.fromasm.imprecise
+++ b/test/min.fromasm.imprecise
@@ -24,8 +24,6 @@
(nop)
)
(func $ctzzzz (result i32)
- (i32.ctz
- (i32.const 4660)
- )
+ (i32.const 2)
)
)
diff --git a/test/passes/precompute.txt b/test/passes/precompute.txt
new file mode 100644
index 000000000..2e343c7fa
--- /dev/null
+++ b/test/passes/precompute.txt
@@ -0,0 +1,16 @@
+(module
+ (memory 0)
+ (func $x (param $x i32)
+ (i32.const 3)
+ (i32.add
+ (i32.const 1)
+ (get_local $x)
+ )
+ (i32.const 6)
+ (i32.const -1)
+ (i32.const 3)
+ (loop $loop-out0 $in
+ (br $in)
+ )
+ )
+)
diff --git a/test/passes/precompute.wast b/test/passes/precompute.wast
new file mode 100644
index 000000000..0282ac61b
--- /dev/null
+++ b/test/passes/precompute.wast
@@ -0,0 +1,19 @@
+(module
+ (func $x (param $x i32)
+ (i32.add (i32.const 1) (i32.const 2)) ;; precomputable
+ (i32.add (i32.const 1) (get_local $x))
+ (i32.add (i32.const 1) (i32.add (i32.const 2) (i32.const 3))) ;; cascade
+ (i32.sub (i32.const 1) (i32.const 2))
+ (i32.sub
+ (i32.add
+ (i32.const 0)
+ (i32.const 4)
+ )
+ (i32.const 1)
+ )
+ (loop $in ;; infinite loop
+ (br $in)
+ )
+ )
+)
+
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 38d8c2c67..6939b9138 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -207,13 +207,7 @@
)
)
(func $big_uint_div_u (result i32)
- (i32.and
- (i32.div_u
- (i32.const -1)
- (i32.const 2)
- )
- (i32.const -1)
- )
+ (i32.const 2147483647)
)
(func $fr (param $0 f32)
(nop)
@@ -225,10 +219,7 @@
(local $0 f32)
(call_indirect $FUNCSIG$vf
(i32.add
- (i32.and
- (i32.const 1)
- (i32.const 7)
- )
+ (i32.const 1)
(i32.const 8)
)
(f32.neg
@@ -239,10 +230,7 @@
(func $cneg (param $0 f32)
(call_indirect $FUNCSIG$vf
(i32.add
- (i32.and
- (i32.const 1)
- (i32.const 7)
- )
+ (i32.const 1)
(i32.const 8)
)
(get_local $0)
@@ -280,10 +268,7 @@
(func $cneg_nosemicolon
(call_indirect $FUNCSIG$vi
(i32.add
- (i32.and
- (i32.const 1)
- (i32.const 7)
- )
+ (i32.const 1)
(i32.const 8)
)
(i32.const 1)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index b493c66d0..ba8dae715 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -199,13 +199,7 @@
)
)
(func $big_uint_div_u (result i32)
- (i32.and
- (i32.div_u
- (i32.const -1)
- (i32.const 2)
- )
- (i32.const -1)
- )
+ (i32.const 2147483647)
)
(func $fr (param $0 f32)
(nop)
@@ -217,10 +211,7 @@
(local $0 f32)
(call_indirect $FUNCSIG$vf
(i32.add
- (i32.and
- (i32.const 1)
- (i32.const 7)
- )
+ (i32.const 1)
(i32.const 8)
)
(f32.neg
@@ -231,10 +222,7 @@
(func $cneg (param $0 f32)
(call_indirect $FUNCSIG$vf
(i32.add
- (i32.and
- (i32.const 1)
- (i32.const 7)
- )
+ (i32.const 1)
(i32.const 8)
)
(get_local $0)
@@ -272,10 +260,7 @@
(func $cneg_nosemicolon
(call_indirect $FUNCSIG$vi
(i32.add
- (i32.and
- (i32.const 1)
- (i32.const 7)
- )
+ (i32.const 1)
(i32.const 8)
)
(i32.const 1)