Skip to content

Commit e27e635

Browse files
Add support for trapsNeverHappen
1 parent 129a6db commit e27e635

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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: (block
24+
;; CHECK-NEXT: (drop
25+
;; CHECK-NEXT: (local.get $x)
26+
;; CHECK-NEXT: )
27+
;; CHECK-NEXT: (drop
28+
;; CHECK-NEXT: (i32.const 20)
29+
;; CHECK-NEXT: )
30+
;; CHECK-NEXT: )
31+
;; CHECK-NEXT: (unreachable)
32+
;; CHECK-NEXT: )
33+
(func $simple-reaching-trap
34+
(local $x (ref null $A))
35+
(struct.set $A 0
36+
(local.get $x)
37+
(i32.const 10)
38+
)
39+
;; a store reaching a trap may be observable from the outside later
40+
(struct.set $A 0
41+
(local.get $x)
42+
(i32.const 20)
43+
)
44+
(unreachable)
45+
)
46+
47+
;; CHECK: (func $global-trap (type $0)
48+
;; CHECK-NEXT: (drop
49+
;; CHECK-NEXT: (i32.const 10)
50+
;; CHECK-NEXT: )
51+
;; CHECK-NEXT: (if
52+
;; CHECK-NEXT: (i32.const 1)
53+
;; CHECK-NEXT: (then
54+
;; CHECK-NEXT: (unreachable)
55+
;; CHECK-NEXT: )
56+
;; CHECK-NEXT: )
57+
;; CHECK-NEXT: (global.set $global$0
58+
;; CHECK-NEXT: (i32.const 20)
59+
;; CHECK-NEXT: )
60+
;; CHECK-NEXT: )
61+
(func $global-trap
62+
(global.set $global$0
63+
(i32.const 10)
64+
)
65+
66+
;; Conditional trap ignored when trapsNeverHappen.
67+
(if
68+
(i32.const 1)
69+
(then
70+
(unreachable)
71+
)
72+
)
73+
(global.set $global$0
74+
(i32.const 20)
75+
)
76+
)
77+
78+
)

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)