From aab5f274773f4e1567b02e6950b4d22119cf801d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 17 May 2023 09:10:08 -0700 Subject: EffectAnalyzer: Do not clear break targets before walk()/visit() (#5723) We depend on repeated calls to walk/visit accumulating effects, so this was a bug; if we want to clear stuff then we create a new EffectAnalyzer. Removing that fixes the attached testcase. Also added a unit test. --- test/lit/passes/optimize-instructions-gc.wast | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/lit') diff --git a/test/lit/passes/optimize-instructions-gc.wast b/test/lit/passes/optimize-instructions-gc.wast index 4535a53b3..7872a10bc 100644 --- a/test/lit/passes/optimize-instructions-gc.wast +++ b/test/lit/passes/optimize-instructions-gc.wast @@ -2499,4 +2499,45 @@ (func $struct_i64_helper (type $struct_i64) (param $0 (ref null struct)) (result i64) (unreachable) ) + + ;; CHECK: (func $array-copy-non-null (type $ref?|$array|_=>_none) (param $x (ref null $array)) + ;; CHECK-NEXT: (block $block + ;; CHECK-NEXT: (array.copy $array $array + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (if (result i32) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: (br $block) + ;; CHECK-NEXT: (i32.const 10) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: (i32.const 1337) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $array-copy-non-null (param $x (ref null $array)) + (block $block + (array.copy $array $array + ;; This cast cannot be removed: while the array.copy will trap anyhow + ;; if $x is null, we might branch out in the if, so removing a trap + ;; here could be noticeable. + (ref.as_non_null + (local.get $x) + ) + (if (result i32) + (i32.const 1) + (br $block) + (i32.const 10) + ) + ;; There are no tricky effects after this, so this cast can be removed. + (ref.as_non_null + (local.get $x) + ) + (i32.const 42) + (i32.const 1337) + ) + ) + ) ) -- cgit v1.2.3