Skip to content

Commit 3861f99

Browse files
committed
Add a disas test for conditional traps
The Wasm-to-CLIF translation is currently suboptimal / we don't have a way to fuse the control-flow equivalent of `trap[n]z` instructions into their single CLIF instruction, which results in worse optimizations and poor codegen. This new test will at least help us track this.
1 parent e471433 commit 3861f99

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/disas/conditional-traps.wat

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
;;! target = "x86_64"
2+
;;! test = "optimize"
3+
4+
(module
5+
;; This function body should ideally get compiled down into a single `trapz`
6+
;; CLIF instruction.
7+
(func (export "trapnz") (param i32)
8+
local.get 0
9+
if
10+
unreachable
11+
end
12+
)
13+
14+
;; And this one into a single `trapnz` instruction.
15+
(func (export "trapz") (param i32)
16+
local.get 0
17+
i32.eqz
18+
if
19+
unreachable
20+
end
21+
)
22+
)
23+
24+
;; function u0:0(i64 vmctx, i64, i32) tail {
25+
;; gv0 = vmctx
26+
;; gv1 = load.i64 notrap aligned readonly gv0+8
27+
;; gv2 = load.i64 notrap aligned gv1+16
28+
;; stack_limit = gv2
29+
;;
30+
;; block0(v0: i64, v1: i64, v2: i32):
31+
;; @002f brif v2, block2, block3
32+
;;
33+
;; block2:
34+
;; @0031 trap user11
35+
;;
36+
;; block3:
37+
;; @0033 jump block1
38+
;;
39+
;; block1:
40+
;; @0033 return
41+
;; }
42+
;;
43+
;; function u0:1(i64 vmctx, i64, i32) tail {
44+
;; gv0 = vmctx
45+
;; gv1 = load.i64 notrap aligned readonly gv0+8
46+
;; gv2 = load.i64 notrap aligned gv1+16
47+
;; stack_limit = gv2
48+
;;
49+
;; block0(v0: i64, v1: i64, v2: i32):
50+
;; v5 = iconst.i32 0
51+
;; @0038 v3 = icmp eq v2, v5 ; v5 = 0
52+
;; @0038 v4 = uextend.i32 v3
53+
;; @0039 brif v4, block2, block3
54+
;;
55+
;; block2:
56+
;; @003b trap user11
57+
;;
58+
;; block3:
59+
;; @003d jump block1
60+
;;
61+
;; block1:
62+
;; @003d return
63+
;; }

0 commit comments

Comments
 (0)