| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. |
| ;; Test that global effects properly track suspension across functions, |
| ;; call chains, cycles, and indirect calls. |
| |
| ;; RUN: foreach %s %t wasm-opt -all --generate-global-effects --vacuum -S -o - | filecheck %s --check-prefix VACUUM |
| ;; RUN: foreach %s %t wasm-opt -all --generate-global-effects --closed-world --vacuum -S -o - | filecheck %s --check-prefix CLOSED-VACUUM |
| ;; RUN: foreach %s %t wasm-opt -all --generate-global-effects --simplify-locals -S -o - | filecheck %s --check-prefix SIMPLIFY |
| |
| (module |
| (memory 1 1) |
| ;; VACUUM: (tag $tag (type $0)) |
| ;; CLOSED-VACUUM: (tag $tag (type $0)) |
| ;; SIMPLIFY: (tag $tag (type $0)) |
| (tag $tag) |
| |
| ;; VACUUM: (func $pure (type $0) |
| ;; VACUUM-NEXT: (nop) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $pure (type $0) |
| ;; CLOSED-VACUUM-NEXT: (nop) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $pure (type $0) |
| ;; SIMPLIFY-NEXT: (nop) |
| ;; SIMPLIFY-NEXT: ) |
| (func $pure |
| (nop) |
| ) |
| |
| ;; VACUUM: (func $caller-of-pure (type $0) |
| ;; VACUUM-NEXT: (nop) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $caller-of-pure (type $0) |
| ;; CLOSED-VACUUM-NEXT: (nop) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $caller-of-pure (type $0) |
| ;; SIMPLIFY-NEXT: (call $pure) |
| ;; SIMPLIFY-NEXT: ) |
| (func $caller-of-pure |
| (call $pure) |
| ) |
| |
| ;; VACUUM: (func $suspending (type $0) |
| ;; VACUUM-NEXT: (suspend $tag) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $suspending (type $0) |
| ;; CLOSED-VACUUM-NEXT: (suspend $tag) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $suspending (type $0) |
| ;; SIMPLIFY-NEXT: (suspend $tag) |
| ;; SIMPLIFY-NEXT: ) |
| (func $suspending |
| (suspend $tag) |
| ) |
| |
| ;; VACUUM: (func $caller-of-suspending (type $0) |
| ;; VACUUM-NEXT: (call $suspending) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $caller-of-suspending (type $0) |
| ;; CLOSED-VACUUM-NEXT: (call $suspending) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $caller-of-suspending (type $0) |
| ;; SIMPLIFY-NEXT: (call $suspending) |
| ;; SIMPLIFY-NEXT: ) |
| (func $caller-of-suspending |
| (call $suspending) |
| ) |
| |
| ;; VACUUM: (func $transitive-caller-of-suspending (type $0) |
| ;; VACUUM-NEXT: (call $caller-of-suspending) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $transitive-caller-of-suspending (type $0) |
| ;; CLOSED-VACUUM-NEXT: (call $caller-of-suspending) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $transitive-caller-of-suspending (type $0) |
| ;; SIMPLIFY-NEXT: (call $caller-of-suspending) |
| ;; SIMPLIFY-NEXT: ) |
| (func $transitive-caller-of-suspending |
| (call $caller-of-suspending) |
| ) |
| |
| ;; Cycles |
| ;; VACUUM: (func $cycle-suspend-a (type $0) |
| ;; VACUUM-NEXT: (call $cycle-suspend-b) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $cycle-suspend-a (type $0) |
| ;; CLOSED-VACUUM-NEXT: (call $cycle-suspend-b) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $cycle-suspend-a (type $0) |
| ;; SIMPLIFY-NEXT: (call $cycle-suspend-b) |
| ;; SIMPLIFY-NEXT: ) |
| (func $cycle-suspend-a |
| (call $cycle-suspend-b) |
| ) |
| |
| ;; VACUUM: (func $cycle-suspend-b (type $0) |
| ;; VACUUM-NEXT: (call $cycle-suspend-a) |
| ;; VACUUM-NEXT: (call $suspending) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $cycle-suspend-b (type $0) |
| ;; CLOSED-VACUUM-NEXT: (call $cycle-suspend-a) |
| ;; CLOSED-VACUUM-NEXT: (call $suspending) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $cycle-suspend-b (type $0) |
| ;; SIMPLIFY-NEXT: (call $cycle-suspend-a) |
| ;; SIMPLIFY-NEXT: (call $suspending) |
| ;; SIMPLIFY-NEXT: ) |
| (func $cycle-suspend-b |
| (call $cycle-suspend-a) |
| (call $suspending) |
| ) |
| |
| ;; Vacuum tests: pure calls should be eliminated, suspending calls preserved. |
| ;; VACUUM: (func $test-vacuum (type $0) |
| ;; VACUUM-NEXT: (call $suspending) |
| ;; VACUUM-NEXT: (call $caller-of-suspending) |
| ;; VACUUM-NEXT: (call $transitive-caller-of-suspending) |
| ;; VACUUM-NEXT: (call $cycle-suspend-a) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $test-vacuum (type $0) |
| ;; CLOSED-VACUUM-NEXT: (call $suspending) |
| ;; CLOSED-VACUUM-NEXT: (call $caller-of-suspending) |
| ;; CLOSED-VACUUM-NEXT: (call $transitive-caller-of-suspending) |
| ;; CLOSED-VACUUM-NEXT: (call $cycle-suspend-a) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $test-vacuum (type $0) |
| ;; SIMPLIFY-NEXT: (call $pure) |
| ;; SIMPLIFY-NEXT: (call $caller-of-pure) |
| ;; SIMPLIFY-NEXT: (call $suspending) |
| ;; SIMPLIFY-NEXT: (call $caller-of-suspending) |
| ;; SIMPLIFY-NEXT: (call $transitive-caller-of-suspending) |
| ;; SIMPLIFY-NEXT: (call $cycle-suspend-a) |
| ;; SIMPLIFY-NEXT: ) |
| (func $test-vacuum |
| ;; Pure calls eliminated: |
| (call $pure) |
| (call $caller-of-pure) |
| |
| ;; Direct, transitive, and cyclic calls to suspend preserved: |
| (call $suspending) |
| (call $caller-of-suspending) |
| (call $transitive-caller-of-suspending) |
| (call $cycle-suspend-a) |
| ) |
| |
| ;; Simplify-locals test: memory access cannot be reordered or eliminated |
| ;; across a call to a function that directly or transitively suspends. |
| ;; VACUUM: (func $test-simplify-memory (type $1) (result i32) |
| ;; VACUUM-NEXT: (local $x i32) |
| ;; VACUUM-NEXT: (local.set $x |
| ;; VACUUM-NEXT: (i32.load |
| ;; VACUUM-NEXT: (i32.const 0) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: (call $caller-of-suspending) |
| ;; VACUUM-NEXT: (local.get $x) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $test-simplify-memory (type $1) (result i32) |
| ;; CLOSED-VACUUM-NEXT: (local $x i32) |
| ;; CLOSED-VACUUM-NEXT: (local.set $x |
| ;; CLOSED-VACUUM-NEXT: (i32.load |
| ;; CLOSED-VACUUM-NEXT: (i32.const 0) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM-NEXT: (call $caller-of-suspending) |
| ;; CLOSED-VACUUM-NEXT: (local.get $x) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $test-simplify-memory (type $1) (result i32) |
| ;; SIMPLIFY-NEXT: (local $x i32) |
| ;; SIMPLIFY-NEXT: (local.set $x |
| ;; SIMPLIFY-NEXT: (i32.load |
| ;; SIMPLIFY-NEXT: (i32.const 0) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: (call $caller-of-suspending) |
| ;; SIMPLIFY-NEXT: (local.get $x) |
| ;; SIMPLIFY-NEXT: ) |
| (func $test-simplify-memory (result i32) |
| ;; Simplify-locals cannot move the load across a possibly-suspending call |
| ;; because the handler might modify memory before resuming. |
| (local $x i32) |
| (local.set $x (i32.load (i32.const 0))) |
| (call $caller-of-suspending) |
| (local.get $x) |
| ) |
| |
| ;; VACUUM: (func $test-simplify-pure (type $1) (result i32) |
| ;; VACUUM-NEXT: (local $x i32) |
| ;; VACUUM-NEXT: (local.set $x |
| ;; VACUUM-NEXT: (i32.load |
| ;; VACUUM-NEXT: (i32.const 0) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: (local.get $x) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $test-simplify-pure (type $1) (result i32) |
| ;; CLOSED-VACUUM-NEXT: (local $x i32) |
| ;; CLOSED-VACUUM-NEXT: (local.set $x |
| ;; CLOSED-VACUUM-NEXT: (i32.load |
| ;; CLOSED-VACUUM-NEXT: (i32.const 0) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM-NEXT: (local.get $x) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $test-simplify-pure (type $1) (result i32) |
| ;; SIMPLIFY-NEXT: (local $x i32) |
| ;; SIMPLIFY-NEXT: (nop) |
| ;; SIMPLIFY-NEXT: (call $caller-of-pure) |
| ;; SIMPLIFY-NEXT: (i32.load |
| ;; SIMPLIFY-NEXT: (i32.const 0) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: ) |
| (func $test-simplify-pure (result i32) |
| ;; When global effects tells us the callee will never suspend (or have other |
| ;; effects), simplify-locals can safely move a load across it. |
| (local $x i32) |
| (local.set $x (i32.load (i32.const 0))) |
| (call $caller-of-pure) |
| (local.get $x) |
| ) |
| ) |
| |
| (module |
| ;; VACUUM: (type $sig-suspending (func (param i32))) |
| |
| ;; VACUUM: (type $sig-pure (func (param i64))) |
| |
| ;; VACUUM: (tag $tag (type $2)) |
| ;; CLOSED-VACUUM: (type $sig-suspending (func (param i32))) |
| |
| ;; CLOSED-VACUUM: (type $sig-pure (func (param i64))) |
| |
| ;; CLOSED-VACUUM: (tag $tag (type $2)) |
| ;; SIMPLIFY: (type $sig-suspending (func (param i32))) |
| |
| ;; SIMPLIFY: (type $sig-pure (func (param i64))) |
| |
| ;; SIMPLIFY: (tag $tag (type $2)) |
| (tag $tag) |
| (type $sig-suspending (func (param i32))) |
| (type $sig-pure (func (param i64))) |
| |
| (table 1 1 funcref) |
| |
| ;; VACUUM: (func $target-suspend (type $sig-suspending) (param $0 i32) |
| ;; VACUUM-NEXT: (suspend $tag) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $target-suspend (type $sig-suspending) (param $0 i32) |
| ;; CLOSED-VACUUM-NEXT: (suspend $tag) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $target-suspend (type $sig-suspending) (param $0 i32) |
| ;; SIMPLIFY-NEXT: (suspend $tag) |
| ;; SIMPLIFY-NEXT: ) |
| (func $target-suspend (export "target-suspend") (type $sig-suspending) (param i32) |
| (suspend $tag) |
| ) |
| |
| ;; VACUUM: (func $target-pure (type $sig-pure) (param $0 i64) |
| ;; VACUUM-NEXT: (nop) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $target-pure (type $sig-pure) (param $0 i64) |
| ;; CLOSED-VACUUM-NEXT: (nop) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $target-pure (type $sig-pure) (param $0 i64) |
| ;; SIMPLIFY-NEXT: (nop) |
| ;; SIMPLIFY-NEXT: ) |
| (func $target-pure (export "target-pure") (type $sig-pure) (param i64) |
| (nop) |
| ) |
| |
| ;; VACUUM: (func $test-indirect-suspend (type $3) (param $ref (ref $sig-suspending)) |
| ;; VACUUM-NEXT: (call_ref $sig-suspending |
| ;; VACUUM-NEXT: (i32.const 0) |
| ;; VACUUM-NEXT: (local.get $ref) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $test-indirect-suspend (type $3) (param $ref (ref $sig-suspending)) |
| ;; CLOSED-VACUUM-NEXT: (call_ref $sig-suspending |
| ;; CLOSED-VACUUM-NEXT: (i32.const 0) |
| ;; CLOSED-VACUUM-NEXT: (local.get $ref) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $test-indirect-suspend (type $3) (param $ref (ref $sig-suspending)) |
| ;; SIMPLIFY-NEXT: (call_ref $sig-suspending |
| ;; SIMPLIFY-NEXT: (i32.const 0) |
| ;; SIMPLIFY-NEXT: (local.get $ref) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: ) |
| (func $test-indirect-suspend (param $ref (ref $sig-suspending)) |
| ;; This has the suspend effect, so it cannot be vacuumed away. |
| (call_ref $sig-suspending (i32.const 0) (local.get $ref)) |
| ) |
| |
| ;; VACUUM: (func $test-indirect-pure (type $4) (param $ref (ref $sig-pure)) |
| ;; VACUUM-NEXT: (call_ref $sig-pure |
| ;; VACUUM-NEXT: (i64.const 0) |
| ;; VACUUM-NEXT: (local.get $ref) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $test-indirect-pure (type $4) (param $ref (ref $sig-pure)) |
| ;; CLOSED-VACUUM-NEXT: (nop) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $test-indirect-pure (type $4) (param $ref (ref $sig-pure)) |
| ;; SIMPLIFY-NEXT: (call_ref $sig-pure |
| ;; SIMPLIFY-NEXT: (i64.const 0) |
| ;; SIMPLIFY-NEXT: (local.get $ref) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: ) |
| (func $test-indirect-pure (param $ref (ref $sig-pure)) |
| ;; With a closed world, global effects tells us that functions of this type |
| ;; never suspend (or have other side effects), so we can vacuum this away. |
| (call_ref $sig-pure (i64.const 0) (local.get $ref)) |
| ) |
| |
| ;; VACUUM: (func $test-vacuum-indirect (type $5) (param $ref1 (ref $sig-suspending)) (param $ref2 (ref $sig-pure)) |
| ;; VACUUM-NEXT: (call $test-indirect-pure |
| ;; VACUUM-NEXT: (local.get $ref2) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: (call $test-indirect-suspend |
| ;; VACUUM-NEXT: (local.get $ref1) |
| ;; VACUUM-NEXT: ) |
| ;; VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM: (func $test-vacuum-indirect (type $5) (param $ref1 (ref $sig-suspending)) (param $ref2 (ref $sig-pure)) |
| ;; CLOSED-VACUUM-NEXT: (call $test-indirect-suspend |
| ;; CLOSED-VACUUM-NEXT: (local.get $ref1) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; CLOSED-VACUUM-NEXT: ) |
| ;; SIMPLIFY: (func $test-vacuum-indirect (type $5) (param $ref1 (ref $sig-suspending)) (param $ref2 (ref $sig-pure)) |
| ;; SIMPLIFY-NEXT: (call $test-indirect-pure |
| ;; SIMPLIFY-NEXT: (local.get $ref2) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: (call $test-indirect-suspend |
| ;; SIMPLIFY-NEXT: (local.get $ref1) |
| ;; SIMPLIFY-NEXT: ) |
| ;; SIMPLIFY-NEXT: ) |
| (func $test-vacuum-indirect (param $ref1 (ref $sig-suspending)) (param $ref2 (ref $sig-pure)) |
| ;; The pure indirect call can be eliminated in closed-world, but not the suspending one. |
| (call $test-indirect-pure (local.get $ref2)) |
| (call $test-indirect-suspend (local.get $ref1)) |
| ) |
| ) |