diff --git a/tests/disas/gc/br-on-cast-fail.wat b/tests/disas/gc/br-on-cast-fail.wat new file mode 100644 index 00000000000..7a2d779d2c9 --- /dev/null +++ b/tests/disas/gc/br-on-cast-fail.wat @@ -0,0 +1,90 @@ +;;! target = "x86_64" +;;! flags = "-W function-references,gc" +;;! test = "optimize" + +(module + (type $s (struct)) + (import "" "f" (func $f)) + (import "" "g" (func $g)) + (func (param anyref) + block (result anyref) + (br_on_cast_fail 0 anyref (ref $s) (local.get 0)) + (call $f) + return + end + (call $g) + return + ) +) +;; function u0:2(i64 vmctx, i64, i32) tail { +;; ss0 = explicit_slot 4, align = 4 +;; gv0 = vmctx +;; gv1 = load.i64 notrap aligned readonly gv0+8 +;; gv2 = load.i64 notrap aligned gv1 +;; gv3 = vmctx +;; sig0 = (i64 vmctx, i32 uext, i32 uext) -> i32 uext system_v +;; sig1 = (i64 vmctx, i64) tail +;; sig2 = (i64 vmctx, i64) tail +;; fn0 = colocated u1:35 sig0 +;; fn1 = u0:0 sig1 +;; fn2 = u0:1 sig2 +;; stack_limit = gv2 +;; +;; block0(v0: i64, v1: i64, v2: i32): +;; v44 = stack_addr.i64 ss0 +;; store notrap v2, v44 +;; v46 = iconst.i32 0 +;; @002e v4 = icmp eq v2, v46 ; v46 = 0 +;; @002e v5 = uextend.i32 v4 +;; @002e v7 = iconst.i32 1 +;; v54 = select v2, v7, v46 ; v7 = 1, v46 = 0 +;; @002e brif v5, block5(v54), block3 +;; +;; block3: +;; v61 = iconst.i32 1 +;; v62 = band.i32 v2, v61 ; v61 = 1 +;; v63 = iconst.i32 0 +;; v64 = select v62, v63, v61 ; v63 = 0, v61 = 1 +;; @002e brif v62, block5(v64), block4 +;; +;; block4: +;; @002e v20 = uextend.i64 v2 +;; @002e v21 = iconst.i64 4 +;; @002e v22 = uadd_overflow_trap v20, v21, user1 ; v21 = 4 +;; @002e v23 = iconst.i64 8 +;; @002e v24 = uadd_overflow_trap v22, v23, user1 ; v23 = 8 +;; @002e v19 = load.i64 notrap aligned readonly v0+48 +;; @002e v25 = icmp ule v24, v19 +;; @002e trapz v25, user1 +;; @002e v18 = load.i64 notrap aligned readonly v0+40 +;; @002e v26 = iadd v18, v22 +;; @002e v27 = load.i32 notrap aligned readonly v26 +;; @002e v15 = load.i64 notrap aligned readonly v0+80 +;; @002e v16 = load.i32 notrap aligned readonly v15 +;; @002e v28 = icmp eq v27, v16 +;; @002e v29 = uextend.i32 v28 +;; @002e brif v29, block7(v29), block6 +;; +;; block6: +;; @002e v31 = call fn0(v0, v27, v16), stack_map=[i32 @ ss0+0] +;; @002e jump block7(v31) +;; +;; block7(v32: i32): +;; @002e jump block5(v32) +;; +;; block5(v33: i32): +;; v40 = load.i32 notrap v44 +;; @002e brif v33, block8, block2 +;; +;; block8: +;; @0034 v35 = load.i64 notrap aligned readonly v0+88 +;; @0034 v36 = load.i64 notrap aligned readonly v0+104 +;; @0034 call_indirect sig1, v35(v36, v0) +;; @0036 return +;; +;; block2: +;; @0038 v38 = load.i64 notrap aligned readonly v0+112 +;; @0038 v39 = load.i64 notrap aligned readonly v0+128 +;; @0038 call_indirect sig2, v38(v39, v0) +;; @003a return +;; } diff --git a/tests/disas/gc/br-on-cast.wat b/tests/disas/gc/br-on-cast.wat new file mode 100644 index 00000000000..d46457d4b43 --- /dev/null +++ b/tests/disas/gc/br-on-cast.wat @@ -0,0 +1,90 @@ +;;! target = "x86_64" +;;! flags = "-W function-references,gc" +;;! test = "optimize" + +(module + (type $s (struct)) + (import "" "f" (func $f)) + (import "" "g" (func $g)) + (func (param anyref) + block (result (ref $s)) + (br_on_cast 0 anyref (ref $s) (local.get 0)) + (call $f) + return + end + (call $g) + return + ) +) +;; function u0:2(i64 vmctx, i64, i32) tail { +;; ss0 = explicit_slot 4, align = 4 +;; gv0 = vmctx +;; gv1 = load.i64 notrap aligned readonly gv0+8 +;; gv2 = load.i64 notrap aligned gv1 +;; gv3 = vmctx +;; sig0 = (i64 vmctx, i32 uext, i32 uext) -> i32 uext system_v +;; sig1 = (i64 vmctx, i64) tail +;; sig2 = (i64 vmctx, i64) tail +;; fn0 = colocated u1:35 sig0 +;; fn1 = u0:0 sig1 +;; fn2 = u0:1 sig2 +;; stack_limit = gv2 +;; +;; block0(v0: i64, v1: i64, v2: i32): +;; v44 = stack_addr.i64 ss0 +;; store notrap v2, v44 +;; v46 = iconst.i32 0 +;; @002f v4 = icmp eq v2, v46 ; v46 = 0 +;; @002f v5 = uextend.i32 v4 +;; @002f v7 = iconst.i32 1 +;; v54 = select v2, v7, v46 ; v7 = 1, v46 = 0 +;; @002f brif v5, block5(v54), block3 +;; +;; block3: +;; v61 = iconst.i32 1 +;; v62 = band.i32 v2, v61 ; v61 = 1 +;; v63 = iconst.i32 0 +;; v64 = select v62, v63, v61 ; v63 = 0, v61 = 1 +;; @002f brif v62, block5(v64), block4 +;; +;; block4: +;; @002f v20 = uextend.i64 v2 +;; @002f v21 = iconst.i64 4 +;; @002f v22 = uadd_overflow_trap v20, v21, user1 ; v21 = 4 +;; @002f v23 = iconst.i64 8 +;; @002f v24 = uadd_overflow_trap v22, v23, user1 ; v23 = 8 +;; @002f v19 = load.i64 notrap aligned readonly v0+48 +;; @002f v25 = icmp ule v24, v19 +;; @002f trapz v25, user1 +;; @002f v18 = load.i64 notrap aligned readonly v0+40 +;; @002f v26 = iadd v18, v22 +;; @002f v27 = load.i32 notrap aligned readonly v26 +;; @002f v15 = load.i64 notrap aligned readonly v0+80 +;; @002f v16 = load.i32 notrap aligned readonly v15 +;; @002f v28 = icmp eq v27, v16 +;; @002f v29 = uextend.i32 v28 +;; @002f brif v29, block7(v29), block6 +;; +;; block6: +;; @002f v31 = call fn0(v0, v27, v16), stack_map=[i32 @ ss0+0] +;; @002f jump block7(v31) +;; +;; block7(v32: i32): +;; @002f jump block5(v32) +;; +;; block5(v33: i32): +;; v40 = load.i32 notrap v44 +;; @002f brif v33, block2, block8 +;; +;; block8: +;; @0035 v35 = load.i64 notrap aligned readonly v0+88 +;; @0035 v36 = load.i64 notrap aligned readonly v0+104 +;; @0035 call_indirect sig1, v35(v36, v0) +;; @0037 return +;; +;; block2: +;; @0039 v38 = load.i64 notrap aligned readonly v0+112 +;; @0039 v39 = load.i64 notrap aligned readonly v0+128 +;; @0039 call_indirect sig2, v38(v39, v0) +;; @003b return +;; } diff --git a/tests/disas/gc/call-indirect-and-subtyping.wat b/tests/disas/gc/call-indirect-and-subtyping.wat new file mode 100644 index 00000000000..992a91d82c7 --- /dev/null +++ b/tests/disas/gc/call-indirect-and-subtyping.wat @@ -0,0 +1,73 @@ +;;! target = "x86_64" +;;! flags = "-W function-references,gc" +;;! test = "optimize" + +(module + (type $t1 (sub (func))) + (type $t2 (sub $t1 (func))) + (type $t3 (sub $t2 (func))) + + (import "" "f2" (func $f2 (type $t2))) + (import "" "f3" (func $f3 (type $t3))) + + (table (ref null $t2) (elem $f2 $f3)) + + (func (export "run") (param i32) + (call_indirect (type $t1) (local.get 0)) + ) +) +;; function u0:2(i64 vmctx, i64, i32) tail { +;; gv0 = vmctx +;; gv1 = load.i64 notrap aligned readonly gv0+8 +;; gv2 = load.i64 notrap aligned gv1 +;; gv3 = vmctx +;; gv4 = load.i64 notrap aligned readonly gv3+136 +;; sig0 = (i64 vmctx, i64) tail +;; sig1 = (i64 vmctx, i32 uext, i64) -> i64 system_v +;; sig2 = (i64 vmctx, i32 uext, i32 uext) -> i32 uext system_v +;; fn0 = colocated u1:9 sig1 +;; fn1 = colocated u1:35 sig2 +;; stack_limit = gv2 +;; +;; block0(v0: i64, v1: i64, v2: i32): +;; @005c v3 = iconst.i32 2 +;; @005c v4 = icmp uge v2, v3 ; v3 = 2 +;; @005c v9 = iconst.i64 0 +;; @005c v6 = load.i64 notrap aligned readonly v0+136 +;; @005c v5 = uextend.i64 v2 +;; v30 = iconst.i64 3 +;; @005c v7 = ishl v5, v30 ; v30 = 3 +;; @005c v8 = iadd v6, v7 +;; @005c v10 = select_spectre_guard v4, v9, v8 ; v9 = 0 +;; @005c v11 = load.i64 user5 aligned table v10 +;; v31 = iconst.i64 -2 +;; @005c v12 = band v11, v31 ; v31 = -2 +;; @005c brif v11, block3(v12), block2 +;; +;; block2 cold: +;; @005c v14 = iconst.i32 0 +;; @005c v17 = call fn0(v0, v14, v5) ; v14 = 0 +;; @005c jump block3(v17) +;; +;; block3(v13: i64): +;; @005c v21 = load.i32 user6 aligned readonly v13+16 +;; @005c v19 = load.i64 notrap aligned readonly v0+80 +;; @005c v20 = load.i32 notrap aligned readonly v19 +;; @005c v22 = icmp eq v21, v20 +;; @005c v23 = uextend.i32 v22 +;; @005c brif v23, block5(v23), block4 +;; +;; block4: +;; @005c v25 = call fn1(v0, v21, v20) +;; @005c jump block5(v25) +;; +;; block5(v26: i32): +;; @005c trapz v26, user7 +;; @005c v27 = load.i64 notrap aligned readonly v13+8 +;; @005c v28 = load.i64 notrap aligned readonly v13+24 +;; @005c call_indirect sig0, v27(v28, v0) +;; @005f jump block1 +;; +;; block1: +;; @005f return +;; } diff --git a/tests/disas/gc/ref-cast.wat b/tests/disas/gc/ref-cast.wat new file mode 100644 index 00000000000..311349e62d4 --- /dev/null +++ b/tests/disas/gc/ref-cast.wat @@ -0,0 +1,70 @@ +;;! target = "x86_64" +;;! flags = "-W function-references,gc" +;;! test = "optimize" + +(module + (type $s (struct)) + (func (param anyref) (result (ref $s)) + (ref.cast (ref $s) (local.get 0)) + ) +) +;; function u0:0(i64 vmctx, i64, i32) -> i32 tail { +;; ss0 = explicit_slot 4, align = 4 +;; gv0 = vmctx +;; gv1 = load.i64 notrap aligned readonly gv0+8 +;; gv2 = load.i64 notrap aligned gv1 +;; gv3 = vmctx +;; sig0 = (i64 vmctx, i32 uext, i32 uext) -> i32 uext system_v +;; fn0 = colocated u1:35 sig0 +;; stack_limit = gv2 +;; +;; block0(v0: i64, v1: i64, v2: i32): +;; v38 = stack_addr.i64 ss0 +;; store notrap v2, v38 +;; v40 = iconst.i32 0 +;; @001e v4 = icmp eq v2, v40 ; v40 = 0 +;; @001e v5 = uextend.i32 v4 +;; @001e v7 = iconst.i32 1 +;; v48 = select v2, v7, v40 ; v7 = 1, v40 = 0 +;; @001e brif v5, block4(v48), block2 +;; +;; block2: +;; v55 = iconst.i32 1 +;; v56 = band.i32 v2, v55 ; v55 = 1 +;; v57 = iconst.i32 0 +;; v58 = select v56, v57, v55 ; v57 = 0, v55 = 1 +;; @001e brif v56, block4(v58), block3 +;; +;; block3: +;; @001e v20 = uextend.i64 v2 +;; @001e v21 = iconst.i64 4 +;; @001e v22 = uadd_overflow_trap v20, v21, user1 ; v21 = 4 +;; @001e v23 = iconst.i64 8 +;; @001e v24 = uadd_overflow_trap v22, v23, user1 ; v23 = 8 +;; @001e v19 = load.i64 notrap aligned readonly v0+48 +;; @001e v25 = icmp ule v24, v19 +;; @001e trapz v25, user1 +;; @001e v18 = load.i64 notrap aligned readonly v0+40 +;; @001e v26 = iadd v18, v22 +;; @001e v27 = load.i32 notrap aligned readonly v26 +;; @001e v15 = load.i64 notrap aligned readonly v0+80 +;; @001e v16 = load.i32 notrap aligned readonly v15 +;; @001e v28 = icmp eq v27, v16 +;; @001e v29 = uextend.i32 v28 +;; @001e brif v29, block6(v29), block5 +;; +;; block5: +;; @001e v31 = call fn0(v0, v27, v16), stack_map=[i32 @ ss0+0] +;; @001e jump block6(v31) +;; +;; block6(v32: i32): +;; @001e jump block4(v32) +;; +;; block4(v33: i32): +;; @001e trapz v33, user19 +;; v34 = load.i32 notrap v38 +;; @0021 jump block1 +;; +;; block1: +;; @0021 return v34 +;; }