blob: c50af32c53ffd1e354c5fec5b5e0469c3ff888bb (
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
|
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --pick-load-signs -all -S -o - | filecheck %s
(module
;; CHECK: (memory $0 16 17 shared)
(memory $0 16 17 shared)
;; CHECK: (func $load-other-use (type $0) (result i32)
;; CHECK-NEXT: (local $temp i32)
;; CHECK-NEXT: (block $label (result i32)
;; CHECK-NEXT: (local.set $temp
;; CHECK-NEXT: (i32.load8_u
;; CHECK-NEXT: (i32.const 22)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.extend8_s
;; CHECK-NEXT: (br_if $label
;; CHECK-NEXT: (local.get $temp)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $load-other-use (result i32)
(local $temp i32)
;; The load here is unsigned, while the value in the local is used in two
;; ways: it is sign-extended, and it is sent on a branch by a br_if. We must
;; not ignore the branch, as if we did then we'd think the only use is signed,
;; and we'd optimize load8_u => load8_s.
(block $label (result i32)
(local.set $temp
(i32.load8_u
(i32.const 22)
)
)
(drop
(i32.extend8_s
(br_if $label
(local.get $temp)
(i32.const 1)
)
)
)
(unreachable)
)
)
;; CHECK: (func $load-valid (type $1)
;; CHECK-NEXT: (local $temp i32)
;; CHECK-NEXT: (local.set $temp
;; CHECK-NEXT: (i32.load8_s
;; CHECK-NEXT: (i32.const 22)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.extend8_s
;; CHECK-NEXT: (local.get $temp)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $load-valid
(local $temp i32)
;; As above, but remove the br_if in the middle. Now this is a valid case to
;; optimize, load8_u => load8_s.
(local.set $temp
(i32.load8_u
(i32.const 22)
)
)
(drop
(i32.extend8_s
(local.get $temp)
)
)
)
)
|