diff options
-rw-r--r-- | src/ir/effects.h | 12 | ||||
-rw-r--r-- | test/lit/passes/vacuum-gc.wast | 51 | ||||
-rw-r--r-- | test/lit/passes/vacuum-tnh.wast | 17 |
3 files changed, 77 insertions, 3 deletions
diff --git a/src/ir/effects.h b/src/ir/effects.h index f24f0ac3f..ced8e63cb 100644 --- a/src/ir/effects.h +++ b/src/ir/effects.h @@ -725,9 +725,15 @@ private: } void visitRefAs(RefAs* curr) { // traps when the arg is not valid - if (curr->value->type.isNullable()) { - parent.implicitTrap = true; - } + parent.implicitTrap = true; + // Note: We could be more precise here and report the lack of a possible + // trap if the input is non-nullable (and also of the right kind for + // RefAsFunc etc.). However, we have optimization passes that will + // remove a RefAs in such a case (in OptimizeInstructions, and also + // Vacuum in trapsNeverHappen mode), so duplicating that code here would + // only help until the next time those optimizations run. As a tradeoff, + // we keep the code here simpler, but it does mean another optimization + // cycle may be needed in some cases. } }; diff --git a/test/lit/passes/vacuum-gc.wast b/test/lit/passes/vacuum-gc.wast new file mode 100644 index 000000000..8ca40bee8 --- /dev/null +++ b/test/lit/passes/vacuum-gc.wast @@ -0,0 +1,51 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. +;; RUN: wasm-opt %s --vacuum -all -S -o - | filecheck %s + +(module + ;; CHECK: (func $drop-ref-as (param $x anyref) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_func + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_data + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_i31 + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $drop-ref-as (param $x anyref) + ;; Without -tnh, we must assume all ref_as* can have a trap effect, and so + ;; we cannot remove anything here. + (drop + (ref.as_non_null + (local.get $x) + ) + ) + (drop + (ref.as_func + (local.get $x) + ) + ) + (drop + (ref.as_data + (local.get $x) + ) + ) + (drop + (ref.as_i31 + (local.get $x) + ) + ) + ) +) diff --git a/test/lit/passes/vacuum-tnh.wast b/test/lit/passes/vacuum-tnh.wast index 4820a55bc..83cb298c2 100644 --- a/test/lit/passes/vacuum-tnh.wast +++ b/test/lit/passes/vacuum-tnh.wast @@ -24,6 +24,23 @@ ) ) + ;; Other ref.as* as well. + (drop + (ref.as_func + (local.get $y) + ) + ) + (drop + (ref.as_data + (local.get $y) + ) + ) + (drop + (ref.as_i31 + (local.get $y) + ) + ) + ;; Ignore unreachable code. (drop (unreachable) |