diff options
-rw-r--r-- | src/ast_utils.h | 1 | ||||
-rw-r--r-- | src/passes/pass.cpp | 2 | ||||
-rw-r--r-- | test/emcc_O2_hello_world.fromasm | 16 | ||||
-rw-r--r-- | test/emcc_O2_hello_world.fromasm.imprecise | 16 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm | 54 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm.imprecise | 54 | ||||
-rw-r--r-- | test/memorygrowth.fromasm | 16 | ||||
-rw-r--r-- | test/memorygrowth.fromasm.imprecise | 16 | ||||
-rw-r--r-- | test/unit.fromasm | 6 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 6 |
10 files changed, 82 insertions, 105 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index 0c2c318e2..8952114bc 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -105,7 +105,6 @@ struct EffectAnalyzer : public PostWalker<EffectAnalyzer, Visitor<EffectAnalyzer || (accessesMemory() && (other.writesMemory || other.calls))) { return true; } - assert(localsWritten.size() + localsRead.size() <= 1); // the code below is fast on that case, of one element vs many for (auto local : localsWritten) { if (other.localsWritten.count(local) || other.localsRead.count(local)) { return true; diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index e43b712e5..babb4635b 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -65,6 +65,7 @@ void PassRunner::addDefaultOptimizationPasses() { add("optimize-instructions"); add("simplify-locals"); add("vacuum"); // previous pass creates garbage + add("remove-unused-brs"); // simplify-locals opens opportunities for phi optimizations add("coalesce-locals"); add("vacuum"); // previous pass creates garbage add("reorder-locals"); @@ -81,6 +82,7 @@ void PassRunner::addDefaultFunctionOptimizationPasses() { add("optimize-instructions"); add("simplify-locals"); add("vacuum"); // previous pass creates garbage + add("remove-unused-brs"); // simplify-locals opens opportunities for phi optimizations add("coalesce-locals"); add("vacuum"); // previous pass creates garbage add("reorder-locals"); diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index ad3f945f3..acbeb2a0b 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -4682,14 +4682,12 @@ ) ) (block - (if + (br_if $do-once$67 + (i32.const 31) (i32.gt_u (get_local $0) (i32.const 16777215) ) - (br $do-once$67 - (i32.const 31) - ) ) (i32.or (i32.and @@ -8190,11 +8188,7 @@ ) ) (set_local $16 - (if - (i32.eq - (get_local $18) - (i32.const 2) - ) + (select (i32.const 0) (i32.sub (get_local $2) @@ -8202,6 +8196,10 @@ (get_local $17) ) ) + (i32.eq + (get_local $18) + (i32.const 2) + ) ) ) ) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index ad3f945f3..acbeb2a0b 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -4682,14 +4682,12 @@ ) ) (block - (if + (br_if $do-once$67 + (i32.const 31) (i32.gt_u (get_local $0) (i32.const 16777215) ) - (br $do-once$67 - (i32.const 31) - ) ) (i32.or (i32.and @@ -8190,11 +8188,7 @@ ) ) (set_local $16 - (if - (i32.eq - (get_local $18) - (i32.const 2) - ) + (select (i32.const 0) (i32.sub (get_local $2) @@ -8202,6 +8196,10 @@ (get_local $17) ) ) + (i32.eq + (get_local $18) + (i32.const 2) + ) ) ) ) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index c7b334e7d..02e6d6002 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -1415,11 +1415,7 @@ ) ) (set_local $14 - (if - (i32.eq - (get_local $16) - (i32.const 2) - ) + (select (i32.const 0) (i32.sub (get_local $2) @@ -1427,6 +1423,10 @@ (get_local $15) ) ) + (i32.eq + (get_local $16) + (i32.const 2) + ) ) ) ) @@ -5422,19 +5422,7 @@ ) (br $while-in$61) ) - (if - (i32.eq - (i32.shr_s - (i32.shl - (i32.load8_s - (get_local $11) - ) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.const 45) - ) + (select (f64.neg (f64.add (get_local $29) @@ -5453,6 +5441,18 @@ ) (get_local $29) ) + (i32.eq + (i32.shr_s + (i32.shl + (i32.load8_s + (get_local $11) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 45) + ) ) ) ) @@ -5611,7 +5611,8 @@ (i32.const 1) ) (block - (if + (br_if $do-once$64 + (get_local $1) (i32.and (get_local $13) (i32.and @@ -5622,9 +5623,6 @@ ) ) ) - (br $do-once$64 - (get_local $1) - ) ) (i32.store8 (get_local $1) @@ -5999,14 +5997,12 @@ ) (br $while-in$73) ) - (if + (br_if $do-once$70 + (get_local $8) (i32.eq (get_local $5) (i32.const 0) ) - (br $do-once$70 - (get_local $8) - ) ) (i32.store (set_local $6 @@ -14941,14 +14937,12 @@ ) (i32.const 0) (block - (if + (br_if $do-once$69 + (i32.const 31) (i32.gt_u (get_local $4) (i32.const 16777215) ) - (br $do-once$69 - (i32.const 31) - ) ) (set_local $1 (i32.shl diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 29492cd2c..b7e3d5f59 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -1413,11 +1413,7 @@ ) ) (set_local $14 - (if - (i32.eq - (get_local $16) - (i32.const 2) - ) + (select (i32.const 0) (i32.sub (get_local $2) @@ -1425,6 +1421,10 @@ (get_local $15) ) ) + (i32.eq + (get_local $16) + (i32.const 2) + ) ) ) ) @@ -5420,19 +5420,7 @@ ) (br $while-in$61) ) - (if - (i32.eq - (i32.shr_s - (i32.shl - (i32.load8_s - (get_local $11) - ) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.const 45) - ) + (select (f64.neg (f64.add (get_local $29) @@ -5451,6 +5439,18 @@ ) (get_local $29) ) + (i32.eq + (i32.shr_s + (i32.shl + (i32.load8_s + (get_local $11) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 45) + ) ) ) ) @@ -5609,7 +5609,8 @@ (i32.const 1) ) (block - (if + (br_if $do-once$64 + (get_local $1) (i32.and (get_local $13) (i32.and @@ -5620,9 +5621,6 @@ ) ) ) - (br $do-once$64 - (get_local $1) - ) ) (i32.store8 (get_local $1) @@ -5997,14 +5995,12 @@ ) (br $while-in$73) ) - (if + (br_if $do-once$70 + (get_local $8) (i32.eq (get_local $5) (i32.const 0) ) - (br $do-once$70 - (get_local $8) - ) ) (i32.store (set_local $6 @@ -14939,14 +14935,12 @@ ) (i32.const 0) (block - (if + (br_if $do-once$69 + (i32.const 31) (i32.gt_u (get_local $4) (i32.const 16777215) ) - (br $do-once$69 - (i32.const 31) - ) ) (set_local $1 (i32.shl diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index 07909b855..3d3f9468b 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -4750,14 +4750,12 @@ ) ) (block - (if + (br_if $do-once$67 + (i32.const 31) (i32.gt_u (get_local $0) (i32.const 16777215) ) - (br $do-once$67 - (i32.const 31) - ) ) (i32.or (i32.and @@ -8245,11 +8243,7 @@ ) ) (set_local $16 - (if - (i32.eq - (get_local $18) - (i32.const 2) - ) + (select (i32.const 0) (i32.sub (get_local $2) @@ -8257,6 +8251,10 @@ (get_local $17) ) ) + (i32.eq + (get_local $18) + (i32.const 2) + ) ) ) ) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index 07909b855..3d3f9468b 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -4750,14 +4750,12 @@ ) ) (block - (if + (br_if $do-once$67 + (i32.const 31) (i32.gt_u (get_local $0) (i32.const 16777215) ) - (br $do-once$67 - (i32.const 31) - ) ) (i32.or (i32.and @@ -8245,11 +8243,7 @@ ) ) (set_local $16 - (if - (i32.eq - (get_local $18) - (i32.const 2) - ) + (select (i32.const 0) (i32.sub (get_local $2) @@ -8257,6 +8251,10 @@ (get_local $17) ) ) + (i32.eq + (get_local $18) + (i32.const 2) + ) ) ) ) diff --git a/test/unit.fromasm b/test/unit.fromasm index 54b790edf..38d8c2c67 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -455,13 +455,11 @@ ) (func $phi (result i32) (block $do-once$0 - (if + (br_if $do-once$0 + (i32.const 0) (call $lb (i32.const 1) ) - (br $do-once$0 - (i32.const 0) - ) ) (i32.const 1) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index b7b25e9b8..b493c66d0 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -447,13 +447,11 @@ ) (func $phi (result i32) (block $do-once$0 - (if + (br_if $do-once$0 + (i32.const 0) (call $lb (i32.const 1) ) - (br $do-once$0 - (i32.const 0) - ) ) (i32.const 1) ) |