diff options
-rw-r--r-- | src/ast_utils.h | 8 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm | 42 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm.imprecise | 42 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm.imprecise.no-opts | 80 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm.no-opts | 80 | ||||
-rw-r--r-- | test/min.fromasm.imprecise.no-opts | 6 | ||||
-rw-r--r-- | test/min.fromasm.no-opts | 6 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 32 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 32 |
9 files changed, 203 insertions, 125 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index 30e1d9a36..ea27c640f 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -789,7 +789,7 @@ struct ExpressionAnalyzer { // Adds drop() operations where necessary. This lets you not worry about adding drop when // generating code. -struct AutoDrop : public WalkerPass<PostWalker<AutoDrop, Visitor<AutoDrop>>> { +struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop, Visitor<AutoDrop>>> { bool isFunctionParallel() override { return true; } Pass* create() override { return new AutoDrop; } @@ -802,6 +802,12 @@ struct AutoDrop : public WalkerPass<PostWalker<AutoDrop, Visitor<AutoDrop>>> { curr->list[i] = Builder(*getModule()).makeDrop(child); } } + auto* last = curr->list.back(); + expressionStack.push_back(last); + if (isConcreteWasmType(last->type) && !ExpressionAnalyzer::isResultUsed(expressionStack, getFunction())) { + curr->list.back() = Builder(*getModule()).makeDrop(last); + } + expressionStack.pop_back(); } void visitFunction(Function* curr) { diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 78c577bbf..ea3485584 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -7290,10 +7290,12 @@ (i32.const 0) ) ) - (call $___fwritex - (i32.const 4143) - (i32.const 1) - (get_local $0) + (drop + (call $___fwritex + (i32.const 4143) + (i32.const 1) + (get_local $0) + ) ) ) ) @@ -7519,10 +7521,12 @@ ) (br $do-once$122) ) - (call $___fwritex - (i32.const 4143) - (i32.const 1) - (get_local $0) + (drop + (call $___fwritex + (i32.const 4143) + (i32.const 1) + (get_local $0) + ) ) ) (block @@ -7645,13 +7649,15 @@ (i32.const 0) ) ) - (call $___fwritex - (get_local $13) - (i32.sub - (get_local $40) + (drop + (call $___fwritex (get_local $13) + (i32.sub + (get_local $40) + (get_local $13) + ) + (get_local $0) ) - (get_local $0) ) ) ) @@ -9446,10 +9452,12 @@ (br $do-once$0) ) ) - (call $___fwritex - (get_local $6) - (get_local $1) - (get_local $0) + (drop + (call $___fwritex + (get_local $6) + (get_local $1) + (get_local $0) + ) ) ) ) diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index d6c27e3c4..06efe55d2 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -7284,10 +7284,12 @@ (i32.const 0) ) ) - (call $___fwritex - (i32.const 4143) - (i32.const 1) - (get_local $0) + (drop + (call $___fwritex + (i32.const 4143) + (i32.const 1) + (get_local $0) + ) ) ) ) @@ -7513,10 +7515,12 @@ ) (br $do-once$122) ) - (call $___fwritex - (i32.const 4143) - (i32.const 1) - (get_local $0) + (drop + (call $___fwritex + (i32.const 4143) + (i32.const 1) + (get_local $0) + ) ) ) (block @@ -7639,13 +7643,15 @@ (i32.const 0) ) ) - (call $___fwritex - (get_local $13) - (i32.sub - (get_local $40) + (drop + (call $___fwritex (get_local $13) + (i32.sub + (get_local $40) + (get_local $13) + ) + (get_local $0) ) - (get_local $0) ) ) ) @@ -9440,10 +9446,12 @@ (br $do-once$0) ) ) - (call $___fwritex - (get_local $6) - (get_local $1) - (get_local $0) + (drop + (call $___fwritex + (get_local $6) + (get_local $1) + (get_local $0) + ) ) ) ) diff --git a/test/emcc_hello_world.fromasm.imprecise.no-opts b/test/emcc_hello_world.fromasm.imprecise.no-opts index 298b05867..5e469d9bb 100644 --- a/test/emcc_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_hello_world.fromasm.imprecise.no-opts @@ -4670,16 +4670,18 @@ (get_local $$sub$ptr$rhs$cast) ) ) - (call_indirect $FUNCSIG$iiii - (get_local $$f) - (get_local $$sub$ptr$sub) - (i32.const 1) - (i32.add - (i32.and - (get_local $$6) - (i32.const 7) + (drop + (call_indirect $FUNCSIG$iiii + (get_local $$f) + (get_local $$sub$ptr$sub) + (i32.const 1) + (i32.add + (i32.and + (get_local $$6) + (i32.const 7) + ) + (i32.const 2) ) - (i32.const 2) ) ) ) @@ -12421,10 +12423,12 @@ (get_local $$sub$ptr$rhs$cast695$i) ) ) - (call $___fwritex - (get_local $$s668$1$i) - (get_local $$sub$ptr$sub696$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$s668$1$i) + (get_local $$sub$ptr$sub696$i) + (get_local $$f) + ) ) ) ) @@ -12490,10 +12494,12 @@ ) (br $do-once$114) ) - (call $___fwritex - (i32.const 4143) - (i32.const 1) - (get_local $$f) + (drop + (call $___fwritex + (i32.const 4143) + (i32.const 1) + (get_local $$f) + ) ) ) ) @@ -12622,10 +12628,12 @@ (get_local $$p$addr$4489$i) ) ) - (call $___fwritex - (get_local $$s715$0$lcssa$i) - (get_local $$cond732$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$s715$0$lcssa$i) + (get_local $$cond732$i) + (get_local $$f) + ) ) ) ) @@ -12966,10 +12974,12 @@ (get_local $$p$addr$5501$i) ) ) - (call $___fwritex - (get_local $$s753$2$i) - (get_local $$cond800$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$s753$2$i) + (get_local $$cond800$i) + (get_local $$f) + ) ) ) ) @@ -13073,10 +13083,12 @@ (get_local $$sub$ptr$rhs$cast812$i) ) ) - (call $___fwritex - (get_local $$estr$2$i) - (get_local $$sub$ptr$sub813$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$estr$2$i) + (get_local $$sub$ptr$sub813$i) + (get_local $$f) + ) ) ) ) @@ -16443,10 +16455,12 @@ (br $do-once$0) ) ) - (call $___fwritex - (get_local $$pad) - (get_local $$l$addr$0$lcssa21) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$pad) + (get_local $$l$addr$0$lcssa21) + (get_local $$f) + ) ) ) ) diff --git a/test/emcc_hello_world.fromasm.no-opts b/test/emcc_hello_world.fromasm.no-opts index 28e44d8f0..d1295a8bd 100644 --- a/test/emcc_hello_world.fromasm.no-opts +++ b/test/emcc_hello_world.fromasm.no-opts @@ -4676,16 +4676,18 @@ (get_local $$sub$ptr$rhs$cast) ) ) - (call_indirect $FUNCSIG$iiii - (get_local $$f) - (get_local $$sub$ptr$sub) - (i32.const 1) - (i32.add - (i32.and - (get_local $$6) - (i32.const 7) + (drop + (call_indirect $FUNCSIG$iiii + (get_local $$f) + (get_local $$sub$ptr$sub) + (i32.const 1) + (i32.add + (i32.and + (get_local $$6) + (i32.const 7) + ) + (i32.const 2) ) - (i32.const 2) ) ) ) @@ -12427,10 +12429,12 @@ (get_local $$sub$ptr$rhs$cast695$i) ) ) - (call $___fwritex - (get_local $$s668$1$i) - (get_local $$sub$ptr$sub696$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$s668$1$i) + (get_local $$sub$ptr$sub696$i) + (get_local $$f) + ) ) ) ) @@ -12496,10 +12500,12 @@ ) (br $do-once$114) ) - (call $___fwritex - (i32.const 4143) - (i32.const 1) - (get_local $$f) + (drop + (call $___fwritex + (i32.const 4143) + (i32.const 1) + (get_local $$f) + ) ) ) ) @@ -12628,10 +12634,12 @@ (get_local $$p$addr$4489$i) ) ) - (call $___fwritex - (get_local $$s715$0$lcssa$i) - (get_local $$cond732$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$s715$0$lcssa$i) + (get_local $$cond732$i) + (get_local $$f) + ) ) ) ) @@ -12972,10 +12980,12 @@ (get_local $$p$addr$5501$i) ) ) - (call $___fwritex - (get_local $$s753$2$i) - (get_local $$cond800$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$s753$2$i) + (get_local $$cond800$i) + (get_local $$f) + ) ) ) ) @@ -13079,10 +13089,12 @@ (get_local $$sub$ptr$rhs$cast812$i) ) ) - (call $___fwritex - (get_local $$estr$2$i) - (get_local $$sub$ptr$sub813$i) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$estr$2$i) + (get_local $$sub$ptr$sub813$i) + (get_local $$f) + ) ) ) ) @@ -16449,10 +16461,12 @@ (br $do-once$0) ) ) - (call $___fwritex - (get_local $$pad) - (get_local $$l$addr$0$lcssa21) - (get_local $$f) + (drop + (call $___fwritex + (get_local $$pad) + (get_local $$l$addr$0$lcssa21) + (get_local $$f) + ) ) ) ) diff --git a/test/min.fromasm.imprecise.no-opts b/test/min.fromasm.imprecise.no-opts index 9b9d6a353..bde70a203 100644 --- a/test/min.fromasm.imprecise.no-opts +++ b/test/min.fromasm.imprecise.no-opts @@ -45,8 +45,10 @@ ) ) ) - (i32.reinterpret/f32 - (get_local $f) + (drop + (i32.reinterpret/f32 + (get_local $f) + ) ) ) ) diff --git a/test/min.fromasm.no-opts b/test/min.fromasm.no-opts index 9b9d6a353..bde70a203 100644 --- a/test/min.fromasm.no-opts +++ b/test/min.fromasm.no-opts @@ -45,8 +45,10 @@ ) ) ) - (i32.reinterpret/f32 - (get_local $f) + (drop + (i32.reinterpret/f32 + (get_local $f) + ) ) ) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 65f556365..05e93926b 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -371,7 +371,9 @@ (drop (f32.const 5) ) - (f32.const 0) + (drop + (f32.const 0) + ) ) ) ) @@ -611,9 +613,11 @@ (get_local $f) ) ) - (i32.reinterpret/f32 - (f32.demote/f64 - (get_local $d) + (drop + (i32.reinterpret/f32 + (f32.demote/f64 + (get_local $d) + ) ) ) ) @@ -646,10 +650,14 @@ (drop (i32.const 4) ) - (i32.const 5) + (drop + (i32.const 5) + ) ) ) - (i32.const 6) + (drop + (i32.const 6) + ) ) ) (i32.const 7) @@ -712,13 +720,17 @@ (i32.const 4) ) ) - (call $lb - (i32.const 5) + (drop + (call $lb + (i32.const 5) + ) ) ) ) - (call $lb - (i32.const 6) + (drop + (call $lb + (i32.const 6) + ) ) ) ) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index a170b7676..ae894c99e 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -377,7 +377,9 @@ (drop (f32.const 5) ) - (f32.const 0) + (drop + (f32.const 0) + ) ) ) ) @@ -617,9 +619,11 @@ (get_local $f) ) ) - (i32.reinterpret/f32 - (f32.demote/f64 - (get_local $d) + (drop + (i32.reinterpret/f32 + (f32.demote/f64 + (get_local $d) + ) ) ) ) @@ -652,10 +656,14 @@ (drop (i32.const 4) ) - (i32.const 5) + (drop + (i32.const 5) + ) ) ) - (i32.const 6) + (drop + (i32.const 6) + ) ) ) (i32.const 7) @@ -718,13 +726,17 @@ (i32.const 4) ) ) - (call $lb - (i32.const 5) + (drop + (call $lb + (i32.const 5) + ) ) ) ) - (call $lb - (i32.const 6) + (drop + (call $lb + (i32.const 6) + ) ) ) ) |