diff options
-rw-r--r-- | src/passes/Vacuum.cpp | 2 | ||||
-rw-r--r-- | test/passes/vacuum.txt | 29 | ||||
-rw-r--r-- | test/passes/vacuum.wast | 11 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 4e47ad9a3..64c7f276a 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -49,6 +49,8 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> { // 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) { + // an unreachable node must not be changed + if (curr->type == unreachable) return curr; while (1) { switch (curr->_id) { case Expression::Id::NopId: return nullptr; // never needed diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt index d1a388333..ec6e3ad44 100644 --- a/test/passes/vacuum.txt +++ b/test/passes/vacuum.txt @@ -28,16 +28,25 @@ (nop) ) (func $unary (type $2) (result f32) - (unreachable) + (f32.abs + (unreachable) + ) ) (func $binary (type $2) (result f32) (drop - (unreachable) + (f32.add + (unreachable) + (f32.const 3) + ) ) ) (func $select (type $3) (result i32) (drop - (unreachable) + (select + (unreachable) + (i32.const 4) + (i32.const 5) + ) ) ) (func $block-to-one (type $0) @@ -198,4 +207,18 @@ (local $2 i32) (nop) ) + (func $a (type $0) + (block $block + (i32.store + (i32.const 1) + (i32.const 2) + ) + (f64.div + (f64.const -nan:0xfffffffffa361) + (loop $label$1 + (br $label$1) + ) + ) + ) + ) ) diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast index c1a84d646..20bbfe625 100644 --- a/test/passes/vacuum.wast +++ b/test/passes/vacuum.wast @@ -509,4 +509,15 @@ ) ) ) + (func $a + (block + (i32.store (i32.const 1) (i32.const 2)) + (f64.div + (f64.const -nan:0xfffffffffa361) + (loop $label$1 ;; unreachable, so the div is too. keep + (br $label$1) + ) + ) + ) + ) ) |