diff options
author | Max Graey <maxgraey@gmail.com> | 2021-10-14 02:44:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 16:44:56 -0700 |
commit | bf4b4b2012992a5e8f59359d0dd6c89df1993cca (patch) | |
tree | 3b1cfec40511739f7e37f12a8fa285d8bd13c3a6 | |
parent | c1031ad28382adc240d2d9198e3a2e3ccaccbb3a (diff) | |
download | binaryen-bf4b4b2012992a5e8f59359d0dd6c89df1993cca.tar.gz binaryen-bf4b4b2012992a5e8f59359d0dd6c89df1993cca.tar.bz2 binaryen-bf4b4b2012992a5e8f59359d0dd6c89df1993cca.zip |
[Selectify] Increase TooCostlyToRunUnconditionally from 7 to 9 (#4228)
This makes Binaryen match LLVM on a real-world case, which is probably
the safest heuristic to use.
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 5 | ||||
-rw-r--r-- | test/lit/passes/remove-unused-brs.wast | 53 | ||||
-rw-r--r-- | test/passes/remove-unused-brs_enable-multivalue.txt | 10 |
3 files changed, 59 insertions, 9 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index cbad81247..01c465f18 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -80,7 +80,10 @@ static bool canTurnIfIntoBrIf(Expression* ifCondition, return !EffectAnalyzer(options, wasm, ifCondition).invalidates(value); } -const Index TooCostlyToRunUnconditionally = 7; +// This leads to similar choices as LLVM does. +// See https://github.com/WebAssembly/binaryen/pull/4228 +// It can be tuned more later. +const Index TooCostlyToRunUnconditionally = 9; // Check if it is not worth it to run code unconditionally. This // assumes we are trying to run two expressions where previously diff --git a/test/lit/passes/remove-unused-brs.wast b/test/lit/passes/remove-unused-brs.wast index e5b29d2e6..3c5d49988 100644 --- a/test/lit/passes/remove-unused-brs.wast +++ b/test/lit/passes/remove-unused-brs.wast @@ -29,6 +29,51 @@ ) ) + ;; CHECK: (func $selectify-simple (param $0 i32) (result i32) + ;; CHECK-NEXT: (select + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: (i32.lt_u + ;; CHECK-NEXT: (i32.sub + ;; CHECK-NEXT: (i32.or + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: (i32.const 32) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 97) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 6) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.lt_u + ;; CHECK-NEXT: (i32.sub + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: (i32.const 48) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 10) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $selectify-simple (param $0 i32) (result i32) + (if (result i32) + (i32.lt_u + (i32.sub + (local.get $0) + (i32.const 48) + ) + (i32.const 10) + ) + (i32.const 1) + (i32.lt_u + (i32.sub + (i32.or + (local.get $0) + (i32.const 32) + ) + (i32.const 97) + ) + (i32.const 6) + ) + ) + ) + ;; CHECK: (func $restructure-br_if (param $x i32) (result i32) ;; CHECK-NEXT: (if (result i32) ;; CHECK-NEXT: (local.get $x) @@ -410,7 +455,9 @@ ;; CHECK-NEXT: (i32.eqz ;; CHECK-NEXT: (i32.eqz ;; CHECK-NEXT: (i32.eqz - ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) @@ -432,9 +479,9 @@ (i32.const 1) ) (if - (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz + (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (i32.eqz (local.get $x) - )))))))) + ))))))))) (call $if-of-if-but-too-costly) ) ) diff --git a/test/passes/remove-unused-brs_enable-multivalue.txt b/test/passes/remove-unused-brs_enable-multivalue.txt index 46938f784..cf8ad7ec2 100644 --- a/test/passes/remove-unused-brs_enable-multivalue.txt +++ b/test/passes/remove-unused-brs_enable-multivalue.txt @@ -2355,11 +2355,7 @@ ) (func $selectify (param $x i32) (drop - (if (result i32) - (i32.eq - (local.get $x) - (i32.const 1) - ) + (select (i32.mul (i32.const 2) (i32.const 3) @@ -2368,6 +2364,10 @@ (i32.const 2) (i32.const 3) ) + (i32.eq + (local.get $x) + (i32.const 1) + ) ) ) (drop |