summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/SimplifyLocals.cpp3
-rw-r--r--src/passes/Vacuum.cpp119
-rw-r--r--test/emcc_O2_hello_world.fromasm114
-rw-r--r--test/emcc_O2_hello_world.fromasm.imprecise114
-rw-r--r--test/emcc_hello_world.fromasm16
-rw-r--r--test/emcc_hello_world.fromasm.imprecise16
-rw-r--r--test/example/c-api-kitchen-sink.txt95
-rw-r--r--test/memorygrowth.fromasm2
-rw-r--r--test/memorygrowth.fromasm.imprecise2
-rw-r--r--test/min.fromasm12
-rw-r--r--test/min.fromasm.imprecise12
-rw-r--r--test/passes/vacuum.txt72
-rw-r--r--test/passes/vacuum.wast54
-rw-r--r--test/unit.fromasm111
-rw-r--r--test/unit.fromasm.imprecise112
15 files changed, 342 insertions, 512 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index fbd1e7e57..dac6cfa65 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -26,8 +26,7 @@
// removing multiple set_locals and replacing them with one that the
// block returns to. Further optimization rounds then have the opportunity
// to remove that set_local as well. TODO: support partial traces; right
-// now, whenever control flow splits, we invalidate everything. This is
-// enough for SSA form, but not otherwise.
+// now, whenever control flow splits, we invalidate everything.
//
// After this pass, some locals may be completely unused. reorder-locals
// can get rid of those (the operation is trivial there after it sorts by use
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 458ce63ca..6d6f1490a 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -30,25 +30,119 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum, Visitor<Vacuum>>> {
std::vector<Expression*> expressionStack;
- bool isDead(Expression* curr, bool resultMayBeUsed) {
- if (curr->is<Nop>()) return true;
- // dead get_locals may be generated from coalesce-locals
- if (curr->is<GetLocal>() && (!resultMayBeUsed || !ExpressionAnalyzer::isResultUsed(expressionStack, getFunction()))) return true;
- // TODO: more dead code
- return false;
+ // returns nullptr if curr is dead, curr if it must stay as is, or another node if it can be replaced
+ Expression* optimize(Expression* curr, bool resultUsed) {
+ while (1) {
+ switch (curr->_id) {
+ case Expression::Id::NopId: return nullptr; // never needed
+
+ case Expression::Id::BlockId: return curr; // not always needed, but handled in visitBlock()
+ case Expression::Id::IfId: return curr; // not always needed, but handled in visitIf()
+ case Expression::Id::LoopId: return curr; // not always needed, but handled in visitLoop()
+
+ case Expression::Id::BreakId:
+ case Expression::Id::SwitchId:
+ case Expression::Id::CallId:
+ case Expression::Id::CallImportId:
+ case Expression::Id::CallIndirectId:
+ case Expression::Id::SetLocalId:
+ case Expression::Id::LoadId:
+ case Expression::Id::StoreId:
+ case Expression::Id::ReturnId:
+ case Expression::Id::HostId:
+ case Expression::Id::UnreachableId: return curr; // always needed
+
+ case Expression::Id::ConstId:
+ case Expression::Id::GetLocalId:
+ case Expression::Id::UnaryId:
+ case Expression::Id::BinaryId:
+ case Expression::Id::SelectId: {
+ if (resultUsed) {
+ return curr; // used, keep it
+ }
+ // result is not used, perhaps it is dead
+ if (curr->is<Const>() || curr->is<GetLocal>()) {
+ return nullptr;
+ }
+ // for unary, binary, and select, we need to check their arguments for side effects
+ if (auto* unary = curr->dynCast<Unary>()) {
+ if (EffectAnalyzer(unary->value).hasSideEffects()) {
+ curr = unary->value;
+ continue;
+ } else {
+ return nullptr;
+ }
+ } else if (auto* binary = curr->dynCast<Binary>()) {
+ if (EffectAnalyzer(binary->left).hasSideEffects()) {
+ if (EffectAnalyzer(binary->right).hasSideEffects()) {
+ return curr; // leave them
+ } else {
+ curr = binary->left;
+ continue;
+ }
+ } else {
+ if (EffectAnalyzer(binary->right).hasSideEffects()) {
+ curr = binary->right;
+ continue;
+ } else {
+ return nullptr;
+ }
+ }
+ } else {
+ // TODO: if two have side effects, we could replace the select with say an add?
+ auto* select = curr->cast<Select>();
+ if (EffectAnalyzer(select->ifTrue).hasSideEffects()) {
+ if (EffectAnalyzer(select->ifFalse).hasSideEffects()) {
+ return curr; // leave them
+ } else {
+ if (EffectAnalyzer(select->condition).hasSideEffects()) {
+ return curr; // leave them
+ } else {
+ curr = select->ifTrue;
+ continue;
+ }
+ }
+ } else {
+ if (EffectAnalyzer(select->ifFalse).hasSideEffects()) {
+ if (EffectAnalyzer(select->condition).hasSideEffects()) {
+ return curr; // leave them
+ } else {
+ curr = select->ifFalse;
+ continue;
+ }
+ } else {
+ if (EffectAnalyzer(select->condition).hasSideEffects()) {
+ curr = select->condition;
+ continue;
+ } else {
+ return nullptr;
+ }
+ }
+ }
+ }
+ }
+
+ default: WASM_UNREACHABLE();
+ }
+ }
}
void visitBlock(Block *curr) {
// compress out nops and other dead code
+ bool resultUsed = ExpressionAnalyzer::isResultUsed(expressionStack, getFunction());
int skip = 0;
auto& list = curr->list;
size_t size = list.size();
bool needResize = false;
for (size_t z = 0; z < size; z++) {
- if (isDead(list[z], z == size - 1)) {
+ auto* optimized = optimize(list[z], z == size - 1 && resultUsed);
+ if (!optimized) {
skip++;
needResize = true;
} else {
+ if (optimized != list[z]) {
+ list[z] = optimized;
+ }
if (skip > 0) {
list[z - skip] = list[z];
}
@@ -67,7 +161,12 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum, Visitor<Vacuum>>> {
}
if (!curr->name.is()) {
if (list.size() == 1) {
- replaceCurrent(list[0]);
+ // just one element. replace the block, either with it or with a nop if it's not needed
+ if (resultUsed || EffectAnalyzer(list[0]).hasSideEffects()) {
+ replaceCurrent(list[0]);
+ } else {
+ ExpressionManipulator::nop(curr);
+ }
} else if (list.size() == 0) {
ExpressionManipulator::nop(curr);
}
@@ -93,6 +192,10 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum, Visitor<Vacuum>>> {
}
}
+ void visitLoop(Loop* curr) {
+ if (curr->body->is<Nop>()) ExpressionManipulator::nop(curr);
+ }
+
static void visitPre(Vacuum* self, Expression** currp) {
self->expressionStack.push_back(*currp);
}
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index d132a15c2..838184cf4 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -1905,7 +1905,6 @@
(set_local $30
(get_local $6)
)
- (i32.const 90)
(br $while-in$20)
)
)
@@ -1922,7 +1921,6 @@
(set_local $30
(get_local $6)
)
- (i32.const 90)
)
(block
(set_local $7
@@ -3112,23 +3110,14 @@
)
(i32.const 0)
)
- (i32.or
- (i32.le_u
- (set_local $14
- (i32.add
- (set_local $26
- (i32.load
- (i32.const 608)
- )
- )
- (get_local $7)
+ (set_local $14
+ (i32.add
+ (set_local $26
+ (i32.load
+ (i32.const 608)
)
)
- (get_local $26)
- )
- (i32.gt_u
- (get_local $14)
- (get_local $9)
+ (get_local $7)
)
)
(i32.const 0)
@@ -3170,19 +3159,13 @@
)
(get_local $9)
)
- (i32.gt_u
- (i32.add
- (get_local $26)
- (i32.load
- (set_local $11
- (i32.add
- (get_local $14)
- (i32.const 4)
- )
- )
+ (i32.load
+ (set_local $11
+ (i32.add
+ (get_local $14)
+ (i32.const 4)
)
)
- (get_local $9)
)
(i32.const 0)
)
@@ -3287,13 +3270,10 @@
(get_local $8)
(i32.const 173)
)
- (i32.ne
- (set_local $9
- (call_import $_sbrk
- (i32.const 0)
- )
+ (set_local $9
+ (call_import $_sbrk
+ (i32.const 0)
)
- (i32.const -1)
)
(i32.const 0)
)
@@ -3569,16 +3549,10 @@
)
(i32.const 0)
)
- (i32.gt_u
- (set_local $13
- (i32.sub
- (get_local $7)
- (get_local $3)
- )
- )
- (i32.add
- (get_local $0)
- (i32.const 40)
+ (set_local $13
+ (i32.sub
+ (get_local $7)
+ (get_local $3)
)
)
(i32.const 0)
@@ -5067,16 +5041,13 @@
)
(get_local $13)
)
- (i32.gt_u
- (set_local $16
- (i32.add
- (get_local $3)
- (i32.load offset=4
- (get_local $28)
- )
+ (set_local $16
+ (i32.add
+ (get_local $3)
+ (i32.load offset=4
+ (get_local $28)
)
)
- (get_local $13)
)
(i32.const 0)
)
@@ -8854,15 +8825,10 @@
)
(get_local $7)
)
- (i32.ne
- (set_local $10
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
- )
- (i32.load8_s offset=75
- (get_local $0)
+ (set_local $10
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
)
(i32.const 0)
@@ -9361,20 +9327,15 @@
)
(i32.const 10)
)
- (i32.lt_u
- (set_local $2
- (i32.load
- (set_local $4
- (i32.add
- (get_local $1)
- (i32.const 20)
- )
+ (set_local $2
+ (i32.load
+ (set_local $4
+ (i32.add
+ (get_local $1)
+ (i32.const 20)
)
)
)
- (i32.load offset=16
- (get_local $1)
- )
)
(i32.const 0)
)
@@ -9686,12 +9647,9 @@
(i32.const 12)
)
)
- (i32.ne
- (call_import $___syscall54
- (i32.const 54)
- (get_local $3)
- )
- (i32.const 0)
+ (call_import $___syscall54
+ (i32.const 54)
+ (get_local $3)
)
)
(i32.const 0)
diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise
index d132a15c2..838184cf4 100644
--- a/test/emcc_O2_hello_world.fromasm.imprecise
+++ b/test/emcc_O2_hello_world.fromasm.imprecise
@@ -1905,7 +1905,6 @@
(set_local $30
(get_local $6)
)
- (i32.const 90)
(br $while-in$20)
)
)
@@ -1922,7 +1921,6 @@
(set_local $30
(get_local $6)
)
- (i32.const 90)
)
(block
(set_local $7
@@ -3112,23 +3110,14 @@
)
(i32.const 0)
)
- (i32.or
- (i32.le_u
- (set_local $14
- (i32.add
- (set_local $26
- (i32.load
- (i32.const 608)
- )
- )
- (get_local $7)
+ (set_local $14
+ (i32.add
+ (set_local $26
+ (i32.load
+ (i32.const 608)
)
)
- (get_local $26)
- )
- (i32.gt_u
- (get_local $14)
- (get_local $9)
+ (get_local $7)
)
)
(i32.const 0)
@@ -3170,19 +3159,13 @@
)
(get_local $9)
)
- (i32.gt_u
- (i32.add
- (get_local $26)
- (i32.load
- (set_local $11
- (i32.add
- (get_local $14)
- (i32.const 4)
- )
- )
+ (i32.load
+ (set_local $11
+ (i32.add
+ (get_local $14)
+ (i32.const 4)
)
)
- (get_local $9)
)
(i32.const 0)
)
@@ -3287,13 +3270,10 @@
(get_local $8)
(i32.const 173)
)
- (i32.ne
- (set_local $9
- (call_import $_sbrk
- (i32.const 0)
- )
+ (set_local $9
+ (call_import $_sbrk
+ (i32.const 0)
)
- (i32.const -1)
)
(i32.const 0)
)
@@ -3569,16 +3549,10 @@
)
(i32.const 0)
)
- (i32.gt_u
- (set_local $13
- (i32.sub
- (get_local $7)
- (get_local $3)
- )
- )
- (i32.add
- (get_local $0)
- (i32.const 40)
+ (set_local $13
+ (i32.sub
+ (get_local $7)
+ (get_local $3)
)
)
(i32.const 0)
@@ -5067,16 +5041,13 @@
)
(get_local $13)
)
- (i32.gt_u
- (set_local $16
- (i32.add
- (get_local $3)
- (i32.load offset=4
- (get_local $28)
- )
+ (set_local $16
+ (i32.add
+ (get_local $3)
+ (i32.load offset=4
+ (get_local $28)
)
)
- (get_local $13)
)
(i32.const 0)
)
@@ -8854,15 +8825,10 @@
)
(get_local $7)
)
- (i32.ne
- (set_local $10
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
- )
- (i32.load8_s offset=75
- (get_local $0)
+ (set_local $10
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
)
(i32.const 0)
@@ -9361,20 +9327,15 @@
)
(i32.const 10)
)
- (i32.lt_u
- (set_local $2
- (i32.load
- (set_local $4
- (i32.add
- (get_local $1)
- (i32.const 20)
- )
+ (set_local $2
+ (i32.load
+ (set_local $4
+ (i32.add
+ (get_local $1)
+ (i32.const 20)
)
)
)
- (i32.load offset=16
- (get_local $1)
- )
)
(i32.const 0)
)
@@ -9686,12 +9647,9 @@
(i32.const 12)
)
)
- (i32.ne
- (call_import $___syscall54
- (i32.const 54)
- (get_local $3)
- )
- (i32.const 0)
+ (call_import $___syscall54
+ (i32.const 54)
+ (get_local $3)
)
)
(i32.const 0)
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index e6dc0b659..8cdbf91fd 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -272,7 +272,6 @@
)
(call_import $abort)
)
- (i32.const 0)
(call $_printf
(i32.const 672)
(get_local $0)
@@ -506,7 +505,6 @@
(i32.const 5)
)
(loop $while-out$2 $while-in$3
- (i32.const 0)
(set_local $1
(get_local $3)
)
@@ -565,7 +563,6 @@
(set_local $3
(get_local $1)
)
- (i32.const 5)
)
)
(br $while-in$3)
@@ -1035,9 +1032,7 @@
(i32.const 0)
)
(func $___unlockfile (param $0 i32)
- (i32.load
- (i32.const 8)
- )
+ (nop)
)
(func $___stdio_write (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
@@ -3360,7 +3355,6 @@
(set_local $70
(get_local $5)
)
- (i32.const 9)
)
(block
(set_local $41
@@ -8113,7 +8107,6 @@
(i32.const 64)
)
(block
- (i32.const 0)
(set_local $7
(i32.and
(get_local $69)
@@ -8300,7 +8293,6 @@
(i32.const 76)
)
(block
- (i32.const 0)
(set_local $34
(call $_fmt_u
(get_local $45)
@@ -11902,7 +11894,6 @@
(set_local $31
(get_local $6)
)
- (i32.const 90)
(br $while-in$20)
)
)
@@ -11934,7 +11925,6 @@
(set_local $31
(get_local $6)
)
- (i32.const 90)
)
)
(br $while-in$20)
@@ -18082,10 +18072,6 @@
(nop)
)
(func $_i64Subtract (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
- (i32.sub
- (get_local $1)
- (get_local $3)
- )
(i32.store
(i32.const 168)
(i32.sub
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 1af75ec39..ef9e9bba0 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -270,7 +270,6 @@
)
(call_import $abort)
)
- (i32.const 0)
(call $_printf
(i32.const 672)
(get_local $0)
@@ -504,7 +503,6 @@
(i32.const 5)
)
(loop $while-out$2 $while-in$3
- (i32.const 0)
(set_local $1
(get_local $3)
)
@@ -563,7 +561,6 @@
(set_local $3
(get_local $1)
)
- (i32.const 5)
)
)
(br $while-in$3)
@@ -1033,9 +1030,7 @@
(i32.const 0)
)
(func $___unlockfile (param $0 i32)
- (i32.load
- (i32.const 8)
- )
+ (nop)
)
(func $___stdio_write (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
@@ -3358,7 +3353,6 @@
(set_local $70
(get_local $5)
)
- (i32.const 9)
)
(block
(set_local $41
@@ -8111,7 +8105,6 @@
(i32.const 64)
)
(block
- (i32.const 0)
(set_local $7
(i32.and
(get_local $69)
@@ -8298,7 +8291,6 @@
(i32.const 76)
)
(block
- (i32.const 0)
(set_local $34
(call $_fmt_u
(get_local $45)
@@ -11900,7 +11892,6 @@
(set_local $31
(get_local $6)
)
- (i32.const 90)
(br $while-in$20)
)
)
@@ -11932,7 +11923,6 @@
(set_local $31
(get_local $6)
)
- (i32.const 90)
)
)
(br $while-in$20)
@@ -18080,10 +18070,6 @@
(nop)
)
(func $_i64Subtract (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
- (i32.sub
- (get_local $1)
- (get_local $3)
- )
(i32.store
(i32.const 168)
(i32.sub
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index c4fb6a4af..118e0c982 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -633,113 +633,57 @@ optimized:
(memory 0)
(type $v (func))
(func $just-one-block (type $v)
- (i32.const 1337)
+ (nop)
)
(func $two-blocks (type $v)
- (i32.const 0)
- (i32.const 1)
+ (nop)
)
(func $two-blocks-plus-code (type $v)
- (i32.const 0)
- (i32.const 77)
- (i32.const 1)
+ (nop)
)
(func $loop (type $v)
(loop $shape$0$break $shape$0$continue
- (i32.const 0)
- (i32.const 1)
(br $shape$0$continue)
)
)
(func $loop-plus-code (type $v)
(loop $shape$0$break $shape$0$continue
- (i32.const 0)
- (i32.const 33)
- (i32.const 1)
- (i32.const -66)
(br $shape$0$continue)
)
)
(func $split (type $v)
- (i32.const 0)
- (select
- (i32.const 1)
- (i32.const 2)
- (i32.const 55)
- )
+ (nop)
)
(func $split-plus-code (type $v)
- (i32.const 0)
- (select
- (block
- (i32.const 10)
- (i32.const 1)
- )
- (block
- (i32.const 20)
- (i32.const 2)
- )
- (i32.const 55)
- )
+ (nop)
)
(func $if (type $v)
- (i32.const 0)
- (if
- (i32.const 55)
- (i32.const 1)
- )
- (i32.const 2)
+ (nop)
)
(func $if-plus-code (type $v)
- (i32.const 0)
- (select
- (block
- (i32.const -1)
- (i32.const 1)
- (i32.const -3)
- )
- (i32.const -2)
- (i32.const 55)
- )
- (i32.const 2)
+ (nop)
)
(func $if-else (type $v)
- (i32.const 0)
- (select
- (i32.const 1)
- (i32.const 2)
- (i32.const 55)
- )
- (i32.const 3)
+ (nop)
)
(func $loop-tail (type $v)
(loop $shape$0$break $shape$0$continue
- (i32.const 0)
- (i32.const 1)
(if
(i32.const 10)
(br $shape$0$continue)
(br $shape$0$break)
)
)
- (i32.const 2)
)
(func $nontrivial-loop-plus-phi-to-head (type $v)
(local $0 i32)
- (i32.const 0)
- (i32.const 10)
(loop $shape$1$break $shape$1$continue
- (i32.const 1)
(if
(i32.eqz
(i32.const -2)
)
- (block
- (i32.const 20)
- (br $shape$1$break)
- )
+ (br $shape$1$break)
)
- (i32.const 2)
(if
(i32.const -6)
(block
@@ -748,28 +692,9 @@ optimized:
)
(br $shape$1$break)
)
- (block
- (i32.const 30)
- (br $shape$1$continue)
- )
- )
- )
- (if
- (i32.eq
- (get_local $0)
- (i32.const 4)
- )
- (block
- (i32.const 3)
- (if
- (i32.const -10)
- (i32.const 4)
- )
- (i32.const 5)
- (i32.const 40)
+ (br $shape$1$continue)
)
)
- (i32.const 6)
)
)
module loaded from binary form:
diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm
index 6ba8ef07a..9e2b77330 100644
--- a/test/memorygrowth.fromasm
+++ b/test/memorygrowth.fromasm
@@ -1945,7 +1945,6 @@
(set_local $32
(get_local $1)
)
- (i32.const 90)
(br $while-in$20)
)
)
@@ -1962,7 +1961,6 @@
(set_local $32
(get_local $1)
)
- (i32.const 90)
)
(block
(set_local $16
diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise
index 6ba8ef07a..9e2b77330 100644
--- a/test/memorygrowth.fromasm.imprecise
+++ b/test/memorygrowth.fromasm.imprecise
@@ -1945,7 +1945,6 @@
(set_local $32
(get_local $1)
)
- (i32.const 90)
(br $while-in$20)
)
)
@@ -1962,7 +1961,6 @@
(set_local $32
(get_local $1)
)
- (i32.const 90)
)
(block
(set_local $16
diff --git a/test/min.fromasm b/test/min.fromasm
index 596ed06cf..45b2f8c19 100644
--- a/test/min.fromasm
+++ b/test/min.fromasm
@@ -23,17 +23,7 @@
)
)
(func $bitcasts (param $0 i32) (param $1 f32)
- (f32.reinterpret/i32
- (get_local $0)
- )
- (f64.promote/f32
- (f32.reinterpret/i32
- (get_local $0)
- )
- )
- (i32.reinterpret/f32
- (get_local $1)
- )
+ (nop)
)
(func $ctzzzz (result i32)
(i32.ctz
diff --git a/test/min.fromasm.imprecise b/test/min.fromasm.imprecise
index 596ed06cf..45b2f8c19 100644
--- a/test/min.fromasm.imprecise
+++ b/test/min.fromasm.imprecise
@@ -23,17 +23,7 @@
)
)
(func $bitcasts (param $0 i32) (param $1 f32)
- (f32.reinterpret/i32
- (get_local $0)
- )
- (f64.promote/f32
- (f32.reinterpret/i32
- (get_local $0)
- )
- )
- (i32.reinterpret/f32
- (get_local $1)
- )
+ (nop)
)
(func $ctzzzz (result i32)
(i32.ctz
diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt
index 69cf5301c..cfe2766c8 100644
--- a/test/passes/vacuum.txt
+++ b/test/passes/vacuum.txt
@@ -1,11 +1,7 @@
(module
(memory 256 256)
(func $b
- (i32.const 50)
- (i32.const 51)
- (i32.const 52)
(block $waka1
- (i32.const 53)
(br $waka1)
)
(block $waka2
@@ -26,7 +22,6 @@
(i32.const 102)
(i32.const 103)
)
- (i32.const 104)
)
(func $l
(local $x i32)
@@ -49,4 +44,71 @@
)
)
)
+ (func $loopy (param $0 i32)
+ (nop)
+ )
+ (func $unary (result f32)
+ (unreachable)
+ (f32.abs
+ (f32.const 2)
+ )
+ )
+ (func $binary (result f32)
+ (unreachable)
+ (unreachable)
+ (f32.add
+ (unreachable)
+ (unreachable)
+ )
+ (f32.add
+ (f32.const 5)
+ (f32.const 6)
+ )
+ )
+ (func $select (result i32)
+ (unreachable)
+ (unreachable)
+ (unreachable)
+ (select
+ (unreachable)
+ (unreachable)
+ (i32.const 10)
+ )
+ (select
+ (unreachable)
+ (i32.const 11)
+ (unreachable)
+ )
+ (select
+ (i32.const 12)
+ (unreachable)
+ (unreachable)
+ )
+ (select
+ (unreachable)
+ (unreachable)
+ (unreachable)
+ )
+ (select
+ (i32.const 13)
+ (i32.const 14)
+ (i32.const 15)
+ )
+ )
+ (func $block-to-one
+ (block $block0
+ )
+ (block $block1
+ (unreachable)
+ )
+ (block $block2
+ (unreachable)
+ )
+ (block $block3
+ (unreachable)
+ )
+ (block $block4
+ (unreachable)
+ )
+ )
)
diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast
index 480fafd67..e2e717807 100644
--- a/test/passes/vacuum.wast
+++ b/test/passes/vacuum.wast
@@ -63,5 +63,59 @@
)
)
)
+ (func $loopy (param $0 i32)
+ (loop (nop))
+ (loop
+ (nop)
+ (nop)
+ )
+ (loop
+ (get_local $0)
+ (i32.const 20)
+ )
+ )
+ (func $unary (result f32)
+ (f32.abs (f32.const 1.0)) ;; unneeded position
+ (f32.abs (unreachable)) ;; side effects
+
+ (f32.abs (f32.const 2.0)) ;; return position
+ )
+ (func $binary (result f32)
+ (f32.add (f32.const 1.0) (f32.const 2.0))
+ (f32.add (unreachable) (f32.const 3.0))
+ (f32.add (f32.const 4.0) (unreachable))
+ (f32.add (unreachable) (unreachable))
+
+ (f32.add (f32.const 5.0) (f32.const 6.0))
+ )
+ (func $select (result i32)
+ (select (i32.const 1) (i32.const 2) (i32.const 3))
+ (select (unreachable) (i32.const 4) (i32.const 5))
+ (select (i32.const 6) (unreachable) (i32.const 7))
+ (select (i32.const 8) (i32.const 9) (unreachable))
+ (select (unreachable) (unreachable) (i32.const 10))
+ (select (unreachable) (i32.const 11) (unreachable))
+ (select (i32.const 12) (unreachable) (unreachable))
+ (select (unreachable) (unreachable) (unreachable))
+
+ (select (i32.const 13) (i32.const 14) (i32.const 15))
+ )
+ (func $block-to-one
+ (block
+ (nop) (nop)
+ )
+ (block
+ (nop) (unreachable)
+ )
+ (block
+ (nop) (unreachable) (nop)
+ )
+ (block
+ (unreachable) (nop)
+ )
+ (block
+ (unreachable)
+ )
+ )
)
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 71602edb0..74ef9b968 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -13,35 +13,9 @@
(export "big_negative" $big_negative)
(table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg)
(func $big_negative
- (f64.const -2147483648)
- (f64.const -2147483648)
- (f64.const -21474836480)
- (f64.const 0.039625)
- (f64.const -0.039625)
+ (nop)
)
(func $importedDoubles (result f64)
- (f64.add
- (f64.add
- (f64.add
- (f64.load
- (i32.const 8)
- )
- (f64.load
- (i32.const 16)
- )
- )
- (f64.neg
- (f64.load
- (i32.const 16)
- )
- )
- )
- (f64.neg
- (f64.load
- (i32.const 8)
- )
- )
- )
(if
(i32.gt_s
(i32.load
@@ -129,29 +103,18 @@
(call_import $f64-to-int
(get_local $1)
)
- (f64.convert_s/i32
- (set_local $0
- (call_import $f64-to-int
- (f64.promote/f32
- (get_local $2)
- )
+ (set_local $0
+ (call_import $f64-to-int
+ (f64.promote/f32
+ (get_local $2)
)
)
)
- (f64.convert_u/i32
- (get_local $0)
- )
)
(func $seq
(f64.sub
- (block
- (f64.const 0.1)
- (f64.const 5.1)
- )
- (block
- (f64.const 3.2)
- (f64.const 4.2)
- )
+ (f64.const 5.1)
+ (f64.const 4.2)
)
)
(func $switcher (param $0 i32) (result i32)
@@ -235,7 +198,6 @@
)
(br $label$break$L1)
)
- (i32.const 1)
(br $switch$17)
)
(br $label$break$L3)
@@ -272,37 +234,15 @@
)
(func $fr (param $0 f32)
(local $1 f64)
- (f32.demote/f64
- (get_local $1)
- )
- (f32.const 5)
- (f32.const 0)
- (f32.const 5)
- (f32.const 0)
+ (nop)
)
(func $negZero (result f64)
(f64.const -0)
)
(func $abs
(local $0 i32)
- (select
- (i32.sub
- (i32.const 0)
- (set_local $0
- (i32.const 0)
- )
- )
- (get_local $0)
- (i32.lt_s
- (get_local $0)
- (i32.const 0)
- )
- )
- (f64.abs
- (f64.const 0)
- )
- (f32.abs
- (f32.const 0)
+ (set_local $0
+ (i32.const 0)
)
)
(func $neg
@@ -405,19 +345,7 @@
)
)
(func $ceiling_32_64 (param $0 f32) (param $1 f64)
- (f32.demote/f64
- (f64.ceil
- (get_local $1)
- )
- )
- (f32.mul
- (get_local $0)
- (f32.ceil
- (f32.demote/f64
- (get_local $1)
- )
- )
- )
+ (nop)
)
(func $aborts
(call_import $abort
@@ -451,22 +379,7 @@
)
(func $bitcasts (param $0 i32) (param $1 f32)
(local $2 f64)
- (f32.reinterpret/i32
- (get_local $0)
- )
- (f64.promote/f32
- (f32.reinterpret/i32
- (get_local $0)
- )
- )
- (i32.reinterpret/f32
- (get_local $1)
- )
- (i32.reinterpret/f32
- (f32.demote/f64
- (get_local $2)
- )
- )
+ (nop)
)
(func $z
(nop)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 44fbdcbb4..77ce73239 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -11,35 +11,9 @@
(export "big_negative" $big_negative)
(table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg)
(func $big_negative
- (f64.const -2147483648)
- (f64.const -2147483648)
- (f64.const -21474836480)
- (f64.const 0.039625)
- (f64.const -0.039625)
+ (nop)
)
(func $importedDoubles (result f64)
- (f64.add
- (f64.add
- (f64.add
- (f64.load
- (i32.const 8)
- )
- (f64.load
- (i32.const 16)
- )
- )
- (f64.neg
- (f64.load
- (i32.const 16)
- )
- )
- )
- (f64.neg
- (f64.load
- (i32.const 8)
- )
- )
- )
(if
(i32.gt_s
(i32.load
@@ -124,30 +98,16 @@
(local $0 i32)
(local $1 f64)
(local $2 f32)
- (i32.trunc_s/f64
- (get_local $1)
- )
- (f64.convert_s/i32
- (set_local $0
- (i32.trunc_s/f32
- (get_local $2)
- )
+ (set_local $0
+ (i32.trunc_s/f32
+ (get_local $2)
)
)
- (f64.convert_u/i32
- (get_local $0)
- )
)
(func $seq
(f64.sub
- (block
- (f64.const 0.1)
- (f64.const 5.1)
- )
- (block
- (f64.const 3.2)
- (f64.const 4.2)
- )
+ (f64.const 5.1)
+ (f64.const 4.2)
)
)
(func $switcher (param $0 i32) (result i32)
@@ -231,7 +191,6 @@
)
(br $label$break$L1)
)
- (i32.const 1)
(br $switch$17)
)
(br $label$break$L3)
@@ -268,37 +227,15 @@
)
(func $fr (param $0 f32)
(local $1 f64)
- (f32.demote/f64
- (get_local $1)
- )
- (f32.const 5)
- (f32.const 0)
- (f32.const 5)
- (f32.const 0)
+ (nop)
)
(func $negZero (result f64)
(f64.const -0)
)
(func $abs
(local $0 i32)
- (select
- (i32.sub
- (i32.const 0)
- (set_local $0
- (i32.const 0)
- )
- )
- (get_local $0)
- (i32.lt_s
- (get_local $0)
- (i32.const 0)
- )
- )
- (f64.abs
- (f64.const 0)
- )
- (f32.abs
- (f32.const 0)
+ (set_local $0
+ (i32.const 0)
)
)
(func $neg
@@ -401,19 +338,7 @@
)
)
(func $ceiling_32_64 (param $0 f32) (param $1 f64)
- (f32.demote/f64
- (f64.ceil
- (get_local $1)
- )
- )
- (f32.mul
- (get_local $0)
- (f32.ceil
- (f32.demote/f64
- (get_local $1)
- )
- )
- )
+ (nop)
)
(func $aborts
(call_import $abort
@@ -447,22 +372,7 @@
)
(func $bitcasts (param $0 i32) (param $1 f32)
(local $2 f64)
- (f32.reinterpret/i32
- (get_local $0)
- )
- (f64.promote/f32
- (f32.reinterpret/i32
- (get_local $0)
- )
- )
- (i32.reinterpret/f32
- (get_local $1)
- )
- (i32.reinterpret/f32
- (f32.demote/f64
- (get_local $2)
- )
- )
+ (nop)
)
(func $z
(nop)