Skip to content

Commit f5d9926

Browse files
Add more tests demonstrating different effects beings aggregated
1 parent 7e09feb commit f5d9926

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
;; RUN: foreach %s %t wasm-opt -all --closed-world --generate-global-effects --simplify-locals -S -o - | filecheck %s
3+
4+
;; Tests for aggregating effects from indirect calls in GlobalEffects when
5+
;; --closed-world is true. Continued from global-effects-closed-world.wast.
6+
7+
(module
8+
;; CHECK: (type $indirect-type (sub (func (param i32))))
9+
(type $indirect-type (sub (func (param i32))))
10+
;; CHECK: (type $1 (func (param (ref $indirect-type))))
11+
12+
;; CHECK: (type $indirect-type-sub (sub $indirect-type (func (param i32))))
13+
(type $indirect-type-sub (sub $indirect-type (func (param i32))))
14+
15+
;; CHECK: (global $g1 (mut i32) (i32.const 0))
16+
(global $g1 (mut i32) (i32.const 0))
17+
;; CHECK: (global $g2 (mut i32) (i32.const 0))
18+
(global $g2 (mut i32) (i32.const 0))
19+
;; CHECK: (global $g3 (mut i32) (i32.const 0))
20+
(global $g3 (mut i32) (i32.const 0))
21+
22+
;; CHECK: (export "impl1" (func $impl1))
23+
24+
;; CHECK: (export "impl2" (func $impl2))
25+
26+
;; CHECK: (func $impl1 (type $indirect-type) (param $i32 i32)
27+
;; CHECK-NEXT: (global.set $g1
28+
;; CHECK-NEXT: (local.get $i32)
29+
;; CHECK-NEXT: )
30+
;; CHECK-NEXT: )
31+
(func $impl1 (export "impl1") (type $indirect-type) (param $i32 i32)
32+
(global.set $g1 (local.get $i32))
33+
)
34+
35+
;; CHECK: (func $impl2 (type $indirect-type-sub) (param $i32 i32)
36+
;; CHECK-NEXT: (global.set $g2
37+
;; CHECK-NEXT: (local.get $i32)
38+
;; CHECK-NEXT: )
39+
;; CHECK-NEXT: )
40+
(func $impl2 (export "impl2") (type $indirect-type-sub) (param $i32 i32)
41+
(global.set $g2 (local.get $i32))
42+
)
43+
44+
;; CHECK: (func $caller (type $1) (param $ref (ref $indirect-type))
45+
;; CHECK-NEXT: (call_ref $indirect-type
46+
;; CHECK-NEXT: (i32.const 1)
47+
;; CHECK-NEXT: (local.get $ref)
48+
;; CHECK-NEXT: )
49+
;; CHECK-NEXT: )
50+
(func $caller (param $ref (ref $indirect-type))
51+
;; This inherits effects from $impl1 and $impl2, so may mutate $g1 and $g2.
52+
(call_ref $indirect-type (i32.const 1) (local.get $ref))
53+
)
54+
55+
;; CHECK: (func $merges-multiple-effects (type $1) (param $ref (ref $indirect-type))
56+
;; CHECK-NEXT: (local $x i32)
57+
;; CHECK-NEXT: (local $y i32)
58+
;; CHECK-NEXT: (local $z i32)
59+
;; CHECK-NEXT: (local.set $x
60+
;; CHECK-NEXT: (global.get $g1)
61+
;; CHECK-NEXT: )
62+
;; CHECK-NEXT: (local.set $y
63+
;; CHECK-NEXT: (global.get $g2)
64+
;; CHECK-NEXT: )
65+
;; CHECK-NEXT: (local.set $z
66+
;; CHECK-NEXT: (global.get $g3)
67+
;; CHECK-NEXT: )
68+
;; CHECK-NEXT: (call $caller
69+
;; CHECK-NEXT: (local.get $ref)
70+
;; CHECK-NEXT: )
71+
;; CHECK-NEXT: (drop
72+
;; CHECK-NEXT: (local.get $x)
73+
;; CHECK-NEXT: )
74+
;; CHECK-NEXT: (drop
75+
;; CHECK-NEXT: (local.get $y)
76+
;; CHECK-NEXT: )
77+
;; CHECK-NEXT: (drop
78+
;; CHECK-NEXT: (local.get $z)
79+
;; CHECK-NEXT: )
80+
;; CHECK-NEXT: )
81+
(func $merges-multiple-effects (param $ref (ref $indirect-type))
82+
(local $x i32)
83+
(local $y i32)
84+
(local $z i32)
85+
86+
(local.set $x (global.get $g1))
87+
(local.set $y (global.get $g2))
88+
(local.set $z (global.get $g3))
89+
90+
;; This acts as a barrier for $x and $y, but not $z because
91+
;; $ref may write to $g1 (via $impl1) or $g2 (via $impl2) but not $g3.
92+
;; $z is optimized out and $x and $y are left alone.
93+
(call $caller (local.get $ref))
94+
95+
(drop (local.get $x))
96+
(drop (local.get $y))
97+
(drop (local.get $z))
98+
)
99+
)

test/lit/passes/global-effects-closed-world-tnh.wast

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
22
;; RUN: foreach %s %t wasm-opt -all --closed-world --traps-never-happen --generate-global-effects --vacuum -S -o - | filecheck %s
33

4+
;; Tests for aggregating effects from indirect calls in GlobalEffects when
5+
;; --closed-world is true. Continued from global-effects-closed-world.wast.
6+
47
(module
58
;; CHECK: (type $nopType (func (param i32)))
69
(type $nopType (func (param i32)))

test/lit/passes/global-effects-closed-world.wast

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
22
;; RUN: foreach %s %t wasm-opt -all --closed-world --generate-global-effects --vacuum -S -o - | filecheck %s
33

4+
;; Tests for aggregating effects from indirect calls in GlobalEffects when
5+
;; --closed-world is true. Some more complicated tests are in
6+
;; global-effects-closed-world-simplify-locals.wast.
7+
48
(module
59
;; CHECK: (type $nopType (func (param i32)))
610
(type $nopType (func (param i32)))

0 commit comments

Comments
 (0)