From 64815443cf1a623eee9d187e173a40df6e714034 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Aug 2025 12:35:31 -0700 Subject: [PATCH 1/5] test --- test/lit/passes/local-cse-cont.wast | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/lit/passes/local-cse-cont.wast diff --git a/test/lit/passes/local-cse-cont.wast b/test/lit/passes/local-cse-cont.wast new file mode 100644 index 00000000000..b6c5c03c341 --- /dev/null +++ b/test/lit/passes/local-cse-cont.wast @@ -0,0 +1,23 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. + +;; RUN: foreach %s %t wasm-opt --local-cse -S -o - | filecheck %s + +(module + (type $func (func (result i32))) + (type $cont (cont $func)) + + (func $func (type $func) + (drop + (cont.new $cont + (ref.func $func) + ) + ) + (drop + (cont.new $cont + (ref.func $func) + ) + ) + ) +) + From 4d1e0f77e56902c6721f3095436ed51d20190464 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Aug 2025 12:42:29 -0700 Subject: [PATCH 2/5] fix --- src/ir/properties.cpp | 2 + test/lit/passes/local-cse-cont.wast | 63 ++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/ir/properties.cpp b/src/ir/properties.cpp index d047718850c..ac2229505bd 100644 --- a/src/ir/properties.cpp +++ b/src/ir/properties.cpp @@ -38,6 +38,8 @@ struct GenerativityScanner : public PostWalker { void visitArrayNewData(ArrayNewData* curr) { generative = true; } void visitArrayNewElem(ArrayNewElem* curr) { generative = true; } void visitArrayNewFixed(ArrayNewFixed* curr) { generative = true; } + void visitContNew(ContNew* curr) { generative = true; } + void visitContBind(ContBind* curr) { generative = true; } }; } // anonymous namespace diff --git a/test/lit/passes/local-cse-cont.wast b/test/lit/passes/local-cse-cont.wast index b6c5c03c341..92d61ab5f8e 100644 --- a/test/lit/passes/local-cse-cont.wast +++ b/test/lit/passes/local-cse-cont.wast @@ -1,21 +1,74 @@ ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. ;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. -;; RUN: foreach %s %t wasm-opt --local-cse -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --local-cse -all -S -o - | filecheck %s (module - (type $func (func (result i32))) + ;; CHECK: (type $func (func)) + (type $func (func)) + ;; CHECK: (type $cont (cont $func)) (type $cont (cont $func)) - (func $func (type $func) + ;; CHECK: (type $func-i32 (func (param i32))) + (type $func-i32 (func (param i32))) + ;; CHECK: (type $cont-i32 (cont $func-i32)) + (type $cont-i32 (cont $func-i32)) + + ;; CHECK: (type $4 (func (param (ref $cont-i32)))) + + ;; CHECK: (elem declare func $cont.new) + + ;; CHECK: (func $cont.new (type $func) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (cont.new $cont + ;; CHECK-NEXT: (ref.func $cont.new) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (cont.new $cont + ;; CHECK-NEXT: (ref.func $cont.new) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $cont.new (type $func) + ;; We cannot CSE here, as each of these emits a unique continuation. (drop (cont.new $cont - (ref.func $func) + (ref.func $cont.new) ) ) (drop (cont.new $cont - (ref.func $func) + (ref.func $cont.new) + ) + ) + ) + + ;; CHECK: (func $cont.bind (type $4) (param $cont-i32 (ref $cont-i32)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (cont.bind $cont-i32 $cont + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: (local.get $cont-i32) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (cont.bind $cont-i32 $cont + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: (local.get $cont-i32) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $cont.bind (param $cont-i32 (ref $cont-i32)) + (drop + (cont.bind $cont-i32 $cont + (i32.const 42) + (local.get $cont-i32) + ) + ) + (drop + (cont.bind $cont-i32 $cont + (i32.const 42) + (local.get $cont-i32) ) ) ) From f9b7e04a045e43cfe8d2c36b772fdb0373b295f9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Aug 2025 12:43:00 -0700 Subject: [PATCH 3/5] fix --- scripts/test/fuzzing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test/fuzzing.py b/scripts/test/fuzzing.py index 7f951ce94cc..33bfacfe1f5 100644 --- a/scripts/test/fuzzing.py +++ b/scripts/test/fuzzing.py @@ -109,6 +109,7 @@ 'O3_stack-switching.wast', 'coalesce-locals-stack-switching.wast', 'dce-stack-switching.wast', + 'local-cse-cont.wast', 'precompute-stack-switching.wast', 'unsubtyping-stack-switching.wast', 'vacuum-stack-switching.wast', From 88627b90b62aa36c3081a7f587921f0020482d5a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Aug 2025 12:48:45 -0700 Subject: [PATCH 4/5] fix --- src/ir/properties.cpp | 1 - test/lit/passes/local-cse-cont.wast | 29 ----------------------------- 2 files changed, 30 deletions(-) diff --git a/src/ir/properties.cpp b/src/ir/properties.cpp index ac2229505bd..8bc8c1d8f6f 100644 --- a/src/ir/properties.cpp +++ b/src/ir/properties.cpp @@ -39,7 +39,6 @@ struct GenerativityScanner : public PostWalker { void visitArrayNewElem(ArrayNewElem* curr) { generative = true; } void visitArrayNewFixed(ArrayNewFixed* curr) { generative = true; } void visitContNew(ContNew* curr) { generative = true; } - void visitContBind(ContBind* curr) { generative = true; } }; } // anonymous namespace diff --git a/test/lit/passes/local-cse-cont.wast b/test/lit/passes/local-cse-cont.wast index 92d61ab5f8e..f95b6703f2c 100644 --- a/test/lit/passes/local-cse-cont.wast +++ b/test/lit/passes/local-cse-cont.wast @@ -43,34 +43,5 @@ ) ) ) - - ;; CHECK: (func $cont.bind (type $4) (param $cont-i32 (ref $cont-i32)) - ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (cont.bind $cont-i32 $cont - ;; CHECK-NEXT: (i32.const 42) - ;; CHECK-NEXT: (local.get $cont-i32) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (cont.bind $cont-i32 $cont - ;; CHECK-NEXT: (i32.const 42) - ;; CHECK-NEXT: (local.get $cont-i32) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: ) - (func $cont.bind (param $cont-i32 (ref $cont-i32)) - (drop - (cont.bind $cont-i32 $cont - (i32.const 42) - (local.get $cont-i32) - ) - ) - (drop - (cont.bind $cont-i32 $cont - (i32.const 42) - (local.get $cont-i32) - ) - ) - ) ) From e0787ef7761fa8a4243425a9f636b6afe24360e9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 20 Aug 2025 13:10:58 -0700 Subject: [PATCH 5/5] clean up test --- test/lit/passes/local-cse-cont.wast | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/lit/passes/local-cse-cont.wast b/test/lit/passes/local-cse-cont.wast index f95b6703f2c..77dea17f85b 100644 --- a/test/lit/passes/local-cse-cont.wast +++ b/test/lit/passes/local-cse-cont.wast @@ -9,13 +9,6 @@ ;; CHECK: (type $cont (cont $func)) (type $cont (cont $func)) - ;; CHECK: (type $func-i32 (func (param i32))) - (type $func-i32 (func (param i32))) - ;; CHECK: (type $cont-i32 (cont $func-i32)) - (type $cont-i32 (cont $func-i32)) - - ;; CHECK: (type $4 (func (param (ref $cont-i32)))) - ;; CHECK: (elem declare func $cont.new) ;; CHECK: (func $cont.new (type $func)