forked from WebAssembly/binaryen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dae.wast
133 lines (132 loc) · 2.78 KB
/
dae.wast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(module
(export "a8" (func $a8))
(table 2 2 funcref)
(elem (i32.const 0) $a9 $c8)
(func $a (param $x i32))
(func $b
(call $a (i32.const 1)) ;; best case scenario
)
(func $a1 (param $x i32)
(unreachable)
)
(func $b1
(call $a1 (i32.const 2)) ;; same value in both, so works
)
(func $b11
(call $a1 (i32.const 2))
)
(func $a2 (param $x i32)
(drop (local.get $x))
)
(func $b2
(call $a2 (i32.const 3)) ;; different value!
)
(func $b22
(call $a2 (i32.const 4))
)
(func $a3 (param $x i32)
(drop (i32.const -1)) ;; diff value, but at least unused, so no need to send
)
(func $b3
(call $a3 (i32.const 3))
)
(func $b33
(call $a3 (i32.const 4))
)
(func $a4 (param $x i32) ;; diff value, but with effects
)
(func $b4
(call $a4 (unreachable))
)
(func $b43
(call $a4 (i32.const 4))
)
(func $a5 (param $x i32) (param $y f64) ;; optimize two
(drop (local.get $x))
(drop (local.get $y))
)
(func $b5
(call $a5 (i32.const 1) (f64.const 3.14159))
)
(func $a6 (param $x i32) (param $y f64) ;; optimize just one
(drop (local.get $x))
(drop (local.get $y))
)
(func $b6
(call $a6 (unreachable) (f64.const 3.14159))
)
(func $a7 (param $x i32) (param $y f64) ;; optimize just the other one
(drop (local.get $x))
(drop (local.get $y))
)
(func $b7
(call $a7 (i32.const 1) (unreachable))
)
(func $a8 (param $x i32)) ;; exported, do not optimize
(func $b8
(call $a8 (i32.const 1))
)
(func $a9 (param $x i32)) ;; tabled, do not optimize
(func $b9
(call $a9 (i32.const 1))
)
(func $a10 (param $x i32) ;; recursion
(call $a10 (i32.const 1))
(call $a10 (i32.const 1))
)
(func $a11 (param $x i32) ;; partially successful recursion
(call $a11 (i32.const 1))
(call $a11 (i32.const 2))
)
(func $a12 (param $x i32) ;; unsuccessful recursion
(drop (local.get $x))
(call $a12 (i32.const 1))
(call $a12 (i32.const 2))
)
;; return values
(func $c1
(local $x i32)
(drop (call $c2))
(drop (call $c3))
(drop (call $c3))
(drop (call $c4))
(local.set $x (call $c4))
(drop (call $c5 (unreachable)))
(drop (call $c6))
(drop (call $c7))
(drop (call $c8))
)
(func $c2 (result i32)
(i32.const 1)
)
(func $c3 (result i32)
(i32.const 2)
)
(func $c4 (result i32)
(i32.const 3)
)
(func $c5 (param $x i32) (result i32)
(local.get $x)
)
(func $c6 (result i32)
(unreachable)
)
(func $c7 (result i32)
(return (i32.const 4))
)
(func $c8 (result i32)
(i32.const 5)
)
)
(module ;; both operations at once: remove params and return value
(func "a"
(drop
(call $b
(i32.const 1)
)
)
)
(func $b (param $x i32) (result i32)
(local.get $x)
)
)