From 3fe1823a59dc689d081a7a7e327639c20bf51bbc Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 23 Apr 2021 16:09:35 -0700 Subject: OptimizeInstructions: Do not change unreachability in if/select changes (#3840) For example, (if (result i32) (local.get $x) (return (local.get $y) ) (return (local.get $z) ) ) If we move the returns outside we'd become unreachable, but we should not make such type changes in this pass (they are handled by DCE and Vacuum). (found by the fuzzer) --- test/lit/passes/optimize-instructions.wast | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test') diff --git a/test/lit/passes/optimize-instructions.wast b/test/lit/passes/optimize-instructions.wast index 058c030dd..5b5b44b57 100644 --- a/test/lit/passes/optimize-instructions.wast +++ b/test/lit/passes/optimize-instructions.wast @@ -12188,6 +12188,33 @@ ) ) ) + ;; CHECK: (func $ternary-identical-arms-return-select (param $x i32) (param $y i32) (param $z i32) (result i32) + ;; CHECK-NEXT: (block $block + ;; CHECK-NEXT: (select + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $z) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $ternary-identical-arms-return-select (param $x i32) (param $y i32) (param $z i32) (result i32) + (block $block + ;; we cannot optimize a select currently as the return has side effects + (select + (return + (local.get $x) + ) + (return + (local.get $y) + ) + (local.get $z) + ) + ) + ) ;; CHECK: (func $send-i32 (param $0 i32) ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) @@ -12212,4 +12239,27 @@ ) ) ) + ;; CHECK: (func $if-dont-change-to-unreachable (param $x i32) (param $y i32) (param $z i32) (result i32) + ;; CHECK-NEXT: (if (result i32) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (local.get $z) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $if-dont-change-to-unreachable (param $x i32) (param $y i32) (param $z i32) (result i32) + ;; if we move the returns outside, we'd become unreachable; avoid that. + (if (result i32) + (local.get $x) + (return + (local.get $y) + ) + (return + (local.get $z) + ) + ) + ) ) -- cgit v1.2.3