Skip to content

Commit ee7538a

Browse files
committed
don't remove unreachable nodes in vaccuum, it can alter types, and dce does that anyhow, let it do it's thing
1 parent 812943d commit ee7538a

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/passes/Vacuum.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
4949

5050
// returns nullptr if curr is dead, curr if it must stay as is, or another node if it can be replaced
5151
Expression* optimize(Expression* curr, bool resultUsed) {
52+
// an unreachable node must not be changed
53+
if (curr->type == unreachable) return curr;
5254
while (1) {
5355
switch (curr->_id) {
5456
case Expression::Id::NopId: return nullptr; // never needed

test/passes/vacuum.txt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,25 @@
2828
(nop)
2929
)
3030
(func $unary (type $2) (result f32)
31-
(unreachable)
31+
(f32.abs
32+
(unreachable)
33+
)
3234
)
3335
(func $binary (type $2) (result f32)
3436
(drop
35-
(unreachable)
37+
(f32.add
38+
(unreachable)
39+
(f32.const 3)
40+
)
3641
)
3742
)
3843
(func $select (type $3) (result i32)
3944
(drop
40-
(unreachable)
45+
(select
46+
(unreachable)
47+
(i32.const 4)
48+
(i32.const 5)
49+
)
4150
)
4251
)
4352
(func $block-to-one (type $0)
@@ -198,4 +207,18 @@
198207
(local $2 i32)
199208
(nop)
200209
)
210+
(func $a (type $0)
211+
(block $block
212+
(i32.store
213+
(i32.const 1)
214+
(i32.const 2)
215+
)
216+
(f64.div
217+
(f64.const -nan:0xfffffffffa361)
218+
(loop $label$1
219+
(br $label$1)
220+
)
221+
)
222+
)
223+
)
201224
)

test/passes/vacuum.wast

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,15 @@
509509
)
510510
)
511511
)
512+
(func $a
513+
(block
514+
(i32.store (i32.const 1) (i32.const 2))
515+
(f64.div
516+
(f64.const -nan:0xfffffffffa361)
517+
(loop $label$1 ;; unreachable, so the div is too. keep
518+
(br $label$1)
519+
)
520+
)
521+
)
522+
)
512523
)

0 commit comments

Comments
 (0)