| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. |
| ;; RUN: foreach %s %t wasm-opt -all --dae2 --closed-world -S -o - | filecheck %s |
| |
| (module |
| ;; CHECK: (func $div (type $0) (param $x i32) (param $y i32) |
| ;; CHECK-NEXT: (drop |
| ;; CHECK-NEXT: (i32.div_s |
| ;; CHECK-NEXT: (local.get $x) |
| ;; CHECK-NEXT: (local.get $y) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $div (param $x i32) (param $y i32) (result i32) |
| ;; The possible trap prevents us from removing the parameters, but we can |
| ;; still remove the result. |
| (i32.div_s (local.get $x) (local.get $y)) |
| ) |
| ;; CHECK: (func $caller (type $1) |
| ;; CHECK-NEXT: (call $div |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: (i32.const 0) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| (drop (call $div (i32.const 1) (i32.const 0))) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (global $g (mut i32) (i32.const 0)) |
| (global $g (mut i32) (i32.const 0)) |
| ;; CHECK: (func $div (type $0) (param $x i32) (param $y i32) (result i32) |
| ;; CHECK-NEXT: (i32.div_s |
| ;; CHECK-NEXT: (local.get $x) |
| ;; CHECK-NEXT: (local.get $y) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $div (param $x i32) (param $y i32) (result i32) |
| (i32.div_s (local.get $x) (local.get $y)) |
| ) |
| ;; CHECK: (func $caller (type $2) |
| ;; CHECK-NEXT: (global.set $g |
| ;; CHECK-NEXT: (call $div |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: (i32.const 0) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| ;; Same, but now the result is used, too. |
| (global.set $g (call $div (i32.const 1) (i32.const 0))) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (import "env" "side_effect" (func $side_effect (type $0))) |
| (import "env" "side_effect" (func $side_effect)) |
| ;; CHECK: (func $test (type $1) (param $cond i32) |
| ;; CHECK-NEXT: (drop |
| ;; CHECK-NEXT: (if (result i32) |
| ;; CHECK-NEXT: (local.get $cond) |
| ;; CHECK-NEXT: (then |
| ;; CHECK-NEXT: (call $side_effect) |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: (else |
| ;; CHECK-NEXT: (i32.const 2) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $test (param $cond i32) (result i32) |
| ;; The parameter is used, but we can still remove the result. |
| (if (result i32) |
| (local.get $cond) |
| (then |
| (block (result i32) |
| (call $side_effect) |
| (i32.const 1) |
| ) |
| ) |
| (else |
| (i32.const 2) |
| ) |
| ) |
| ) |
| ;; CHECK: (func $caller (type $0) |
| ;; CHECK-NEXT: (call $test |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| (drop (call $test (i32.const 1))) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (import "env" "side_effect" (func $side_effect (type $0))) |
| (import "env" "side_effect" (func $side_effect)) |
| ;; CHECK: (global $g (mut i32) (i32.const 0)) |
| (global $g (mut i32) (i32.const 0)) |
| ;; CHECK: (func $test (type $1) (param $cond i32) (result i32) |
| ;; CHECK-NEXT: (if (result i32) |
| ;; CHECK-NEXT: (local.get $cond) |
| ;; CHECK-NEXT: (then |
| ;; CHECK-NEXT: (call $side_effect) |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: (else |
| ;; CHECK-NEXT: (i32.const 2) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $test (param $cond i32) (result i32) |
| (if (result i32) (local.get $cond) |
| (then |
| (block (result i32) |
| (call $side_effect) |
| (i32.const 1) |
| ) |
| ) |
| (else |
| (i32.const 2) |
| ) |
| ) |
| ) |
| ;; CHECK: (func $caller (type $0) |
| ;; CHECK-NEXT: (global.set $g |
| ;; CHECK-NEXT: (call $test |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| ;; Same, but now the result is used. |
| (global.set $g (call $test (i32.const 1))) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (func $test (type $0) (param $cond i32) |
| ;; CHECK-NEXT: (drop |
| ;; CHECK-NEXT: (block $label (result i32) |
| ;; CHECK-NEXT: (drop |
| ;; CHECK-NEXT: (br_if $label |
| ;; CHECK-NEXT: (i32.const 42) |
| ;; CHECK-NEXT: (local.get $cond) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: (i32.const 100) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $test (param $cond i32) (result i32) |
| ;; We can drop the unused result returned via a labeled block. |
| (block $label (result i32) |
| (drop |
| (br_if $label (i32.const 42) (local.get $cond)) |
| ) |
| (i32.const 100) |
| ) |
| ) |
| ;; CHECK: (func $caller (type $1) |
| ;; CHECK-NEXT: (call $test |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| (drop (call $test (i32.const 1))) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (global $g (mut i32) (i32.const 0)) |
| (global $g (mut i32) (i32.const 0)) |
| ;; CHECK: (func $test (type $0) (param $cond i32) (result i32) |
| ;; CHECK-NEXT: (block $label (result i32) |
| ;; CHECK-NEXT: (drop |
| ;; CHECK-NEXT: (br_if $label |
| ;; CHECK-NEXT: (i32.const 42) |
| ;; CHECK-NEXT: (local.get $cond) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: (i32.const 100) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $test (param $cond i32) (result i32) |
| (block $label (result i32) |
| (drop |
| (br_if $label (i32.const 42) (local.get $cond)) |
| ) |
| (i32.const 100) |
| ) |
| ) |
| ;; CHECK: (func $caller (type $2) |
| ;; CHECK-NEXT: (global.set $g |
| ;; CHECK-NEXT: (call $test |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| ;; Same, but now the result is used. |
| (global.set $g (call $test (i32.const 1))) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (import "env" "side_effect" (func $side_effect (type $0))) |
| (import "env" "side_effect" (func $side_effect)) |
| ;; CHECK: (tag $tag (type $0)) |
| (tag $tag) |
| ;; CHECK: (func $test (type $0) |
| ;; CHECK-NEXT: (drop |
| ;; CHECK-NEXT: (try (result i32) |
| ;; CHECK-NEXT: (do |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: (catch $tag |
| ;; CHECK-NEXT: (call $side_effect) |
| ;; CHECK-NEXT: (i32.const 2) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $test (result i32) |
| ;; We can drop an unused result returned via a try-catch. |
| (try (result i32) |
| (do (i32.const 1)) |
| (catch $tag |
| (call $side_effect) |
| (i32.const 2) |
| ) |
| ) |
| ) |
| ;; CHECK: (func $caller (type $0) |
| ;; CHECK-NEXT: (call $test) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| (drop (call $test)) |
| ) |
| ) |
| |
| (module |
| ;; CHECK: (import "env" "side_effect" (func $side_effect (type $0))) |
| (import "env" "side_effect" (func $side_effect)) |
| ;; CHECK: (global $g (mut i32) (i32.const 0)) |
| |
| ;; CHECK: (tag $tag (type $0)) |
| (tag $tag) |
| (global $g (mut i32) (i32.const 0)) |
| ;; CHECK: (func $test (type $1) (result i32) |
| ;; CHECK-NEXT: (try (result i32) |
| ;; CHECK-NEXT: (do |
| ;; CHECK-NEXT: (i32.const 1) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: (catch $tag |
| ;; CHECK-NEXT: (call $side_effect) |
| ;; CHECK-NEXT: (i32.const 2) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $test (result i32) |
| (try (result i32) |
| (do (i32.const 1)) |
| (catch $tag |
| (call $side_effect) |
| (i32.const 2) |
| ) |
| ) |
| ) |
| ;; CHECK: (func $caller (type $0) |
| ;; CHECK-NEXT: (global.set $g |
| ;; CHECK-NEXT: (call $test) |
| ;; CHECK-NEXT: ) |
| ;; CHECK-NEXT: ) |
| (func $caller |
| ;; Same, but now the result is used. |
| (global.set $g (call $test)) |
| ) |
| ) |