Skip to content

Commit 5714f71

Browse files
Add support for trapsNeverHappen
1 parent 129a6db commit 5714f71

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

src/passes/DeadStoreElimination.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ struct Logic {
139139
// after a trap) then we could stop assuming any trap can lead to
140140
// access of global data, likely greatly reducing the number of
141141
// barriers.
142-
return currEffects.calls || currEffects.throws() || currEffects.trap ||
142+
return currEffects.calls || currEffects.throws() ||
143+
(!currEffects.trapsNeverHappen && currEffects.trap) ||
143144
currEffects.branchesOut;
144145
};
145146

test/lit/passes/ldse-tnh.wast

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
;; (--remove-unused-names avoids names on blocks, which would hamper the
3+
;; work in getFallthrough, as a name implies possible breaks)
4+
;; RUN: wasm-opt %s --traps-never-happen -all --remove-unused-names --ldse -S -o - | filecheck %s
5+
6+
(module
7+
;; CHECK: (type $A (struct (field (mut i32))))
8+
(type $A (struct (field (mut i32))))
9+
10+
;; CHECK: (global $global$0 (mut i32) (i32.const 0))
11+
(global $global$0 (mut i32) (i32.const 0))
12+
13+
;; CHECK: (func $simple-reaching-trap (type $0)
14+
;; CHECK-NEXT: (local $x (ref null $A))
15+
;; CHECK-NEXT: (block
16+
;; CHECK-NEXT: (drop
17+
;; CHECK-NEXT: (local.get $x)
18+
;; CHECK-NEXT: )
19+
;; CHECK-NEXT: (drop
20+
;; CHECK-NEXT: (i32.const 10)
21+
;; CHECK-NEXT: )
22+
;; CHECK-NEXT: )
23+
;; CHECK-NEXT: (unreachable)
24+
;; CHECK-NEXT: (struct.set $A 0
25+
;; CHECK-NEXT: (local.get $x)
26+
;; CHECK-NEXT: (i32.const 20)
27+
;; CHECK-NEXT: )
28+
;; CHECK-NEXT: )
29+
(func $simple-reaching-trap
30+
(local $x (ref null $A))
31+
32+
;; This would normally not be dead due to the unreachable but we're running with --traps-never-happen
33+
(struct.set $A 0
34+
(local.get $x)
35+
(i32.const 10)
36+
)
37+
38+
(unreachable)
39+
40+
(struct.set $A 0
41+
(local.get $x)
42+
(i32.const 20)
43+
)
44+
)
45+
46+
;; CHECK: (func $global-trap (type $0)
47+
;; CHECK-NEXT: (drop
48+
;; CHECK-NEXT: (i32.const 10)
49+
;; CHECK-NEXT: )
50+
;; CHECK-NEXT: (if
51+
;; CHECK-NEXT: (i32.const 1)
52+
;; CHECK-NEXT: (then
53+
;; CHECK-NEXT: (unreachable)
54+
;; CHECK-NEXT: )
55+
;; CHECK-NEXT: )
56+
;; CHECK-NEXT: (global.set $global$0
57+
;; CHECK-NEXT: (i32.const 20)
58+
;; CHECK-NEXT: )
59+
;; CHECK-NEXT: )
60+
(func $global-trap
61+
(global.set $global$0
62+
(i32.const 10)
63+
)
64+
65+
;; Conditional trap ignored when trapsNeverHappen.
66+
(if
67+
(i32.const 1)
68+
(then
69+
(unreachable)
70+
)
71+
)
72+
(global.set $global$0
73+
(i32.const 20)
74+
)
75+
)
76+
77+
)

test/lit/passes/ldse.wast

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
(type $B (struct (field (mut f64))))
1313
(type $C (struct (field (mut i32)) (field (mut i32))))
1414

15-
(memory 10 10 shared)
16-
1715
;; CHECK: (global $global$0 (mut i32) (i32.const 0))
1816
(global $global$0 (mut i32) (i32.const 0))
1917
;; CHECK: (global $global$1 (mut i32) (i32.const 0))

0 commit comments

Comments
 (0)