blob: 6181a662def12e92deac29be35ae1f3fcac9aca7 (
plain)
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
|
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --vacuum -all -S -o - | filecheck %s
;; Tests vacuuming the entire body of a function. In that case we can ignore
;; effects like a return or changes to locals.
(module
;; CHECK: (func $optimizable (type $0) (param $x i32)
;; CHECK-NEXT: (local $y i32)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $optimizable (param $x i32)
(local $y i32)
;; This entire function body can be optimized out. First, operations on
;; locals are not observable once the function exits.
(local.set $x
(i32.const 1)
)
(local.set $y
(i32.const 2)
)
(drop
(local.get $x)
)
;; Second, a return has no noticeable effect for the caller to notice.
(return)
)
;; CHECK: (func $result (type $1) (param $x i32) (result i32)
;; CHECK-NEXT: (local $y i32)
;; CHECK-NEXT: (local.set $x
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $y
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
;; CHECK-NEXT: (return
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $result (param $x i32) (result i32)
(local $y i32)
;; As above, but this function returns a value, so we cannot optimize here:
;; the value must be computed and returned. (We could in theory remove just
;; the parts that are valid to remove, but other passes will do so anyhow
;; for the code in this test at least.)
(local.set $x
(i32.const 1)
)
(local.set $y
(i32.const 2)
)
(return
(local.get $x)
)
)
;; CHECK: (func $partial (type $0) (param $x i32)
;; CHECK-NEXT: (local $y i32)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $x
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $y
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
;; CHECK-NEXT: (return)
;; CHECK-NEXT: )
(func $partial (param $x i32)
(local $y i32)
;; As above, but with this |if| added with extra possible effects. This
;; prevents optimization. (We could in theory remove just the parts that are
;; valid to remove, but other passes will do so anyhow for the code in this
;; test at least.)
(if
(local.get $x)
(then
(unreachable)
)
)
(local.set $x
(i32.const 1)
)
(local.set $y
(i32.const 2)
)
(drop
(local.get $x)
)
(return)
)
)
|