summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-11-15 10:06:39 -0800
committerGitHub <noreply@github.com>2018-11-15 10:06:39 -0800
commit622cba9c49378f89ca94e05cbbe2af0b0c62ab44 (patch)
tree25d4c0d3837fb8b0f84cd2eebee1414011d7c289
parent892d2d747883aca132d2eb4e3ba5a6b261f944af (diff)
downloadbinaryen-622cba9c49378f89ca94e05cbbe2af0b0c62ab44.tar.gz
binaryen-622cba9c49378f89ca94e05cbbe2af0b0c62ab44.tar.bz2
binaryen-622cba9c49378f89ca94e05cbbe2af0b0c62ab44.zip
Don't try to optimize away unused names in RemoveUnusedBrs (#1750)
Rely on the dedicated pass for that. It's not worth the extra complexity to try, as we can't easily handle all the cases anyhow. Add another run of the dedicated name-removing pass in the default passes.
-rw-r--r--src/passes/RemoveUnusedBrs.cpp1
-rw-r--r--src/passes/pass.cpp3
-rw-r--r--test/debugInfo.fromasm4
-rw-r--r--test/debugInfo.fromasm.clamp4
-rw-r--r--test/debugInfo.fromasm.imprecise4
-rw-r--r--test/emcc_hello_world.fromasm92
-rw-r--r--test/emcc_hello_world.fromasm.clamp92
-rw-r--r--test/emcc_hello_world.fromasm.imprecise92
-rw-r--r--test/passes/O.txt18
-rw-r--r--test/passes/flatten_dfo_O3.txt20
-rw-r--r--test/passes/remove-unused-brs.txt6
-rw-r--r--test/passes/remove-unused-brs_shrink-level=1.txt2
-rw-r--r--test/passes/remove-unused-brs_shrink-level=1_ignore-implicit-traps.txt2
-rw-r--r--test/unit.fromasm45
-rw-r--r--test/unit.fromasm.clamp45
-rw-r--r--test/unit.fromasm.imprecise45
16 files changed, 227 insertions, 248 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index ce839a646..ccdf55794 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -668,7 +668,6 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
builder.makeUnary(EqZInt32, br->condition),
curr
));
- curr->name = Name();
ExpressionManipulator::nop(br);
curr->finalize(curr->type);
} else {
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 577ccd36a..26f771277 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -184,7 +184,8 @@ void PassRunner::addDefaultFunctionOptimizationPasses() {
add("code-folding");
}
add("merge-blocks"); // makes remove-unused-brs more effective
- add("remove-unused-brs"); // coalesce-locals opens opportunities for optimizations
+ add("remove-unused-brs"); // coalesce-locals opens opportunities
+ add("remove-unused-names"); // remove-unused-brs opens opportunities
add("merge-blocks"); // clean up remove-unused-brs new blocks
add("optimize-instructions");
// late propagation
diff --git a/test/debugInfo.fromasm b/test/debugInfo.fromasm
index c9eb61d21..895c032eb 100644
--- a/test/debugInfo.fromasm
+++ b/test/debugInfo.fromasm
@@ -142,7 +142,7 @@
)
(i32.const 1369188723)
)
- (block $switch (result i32)
+ (block (result i32)
(br_if $__rjti$0
(i32.eqz
(i32.sub
@@ -153,7 +153,7 @@
)
(i32.const 0)
)
- (block $switch0 (result i32)
+ (block (result i32)
(br_if $__rjti$0
(i32.eqz
(i32.sub
diff --git a/test/debugInfo.fromasm.clamp b/test/debugInfo.fromasm.clamp
index c9eb61d21..895c032eb 100644
--- a/test/debugInfo.fromasm.clamp
+++ b/test/debugInfo.fromasm.clamp
@@ -142,7 +142,7 @@
)
(i32.const 1369188723)
)
- (block $switch (result i32)
+ (block (result i32)
(br_if $__rjti$0
(i32.eqz
(i32.sub
@@ -153,7 +153,7 @@
)
(i32.const 0)
)
- (block $switch0 (result i32)
+ (block (result i32)
(br_if $__rjti$0
(i32.eqz
(i32.sub
diff --git a/test/debugInfo.fromasm.imprecise b/test/debugInfo.fromasm.imprecise
index a52606e16..a0468d1f5 100644
--- a/test/debugInfo.fromasm.imprecise
+++ b/test/debugInfo.fromasm.imprecise
@@ -129,7 +129,7 @@
)
(i32.const 1369188723)
)
- (block $switch (result i32)
+ (block (result i32)
(br_if $__rjti$0
(i32.eqz
(i32.sub
@@ -140,7 +140,7 @@
)
(i32.const 0)
)
- (block $switch0 (result i32)
+ (block (result i32)
(br_if $__rjti$0
(i32.eqz
(i32.sub
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index c243b2c8e..8b07f24c0 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -170,70 +170,68 @@
)
(block $switch
(block $switch-default
- (block $switch-case0
- (if
- (tee_local $5
- (tee_local $3
- (i32.and
- (tee_local $3
- (call $_bitshift64Lshr
- (tee_local $2
- (i32.load
- (get_global $tempDoublePtr)
- )
+ (if
+ (tee_local $5
+ (tee_local $3
+ (i32.and
+ (tee_local $3
+ (call $_bitshift64Lshr
+ (tee_local $2
+ (i32.load
+ (get_global $tempDoublePtr)
)
- (tee_local $4
- (i32.load offset=4
- (get_global $tempDoublePtr)
- )
+ )
+ (tee_local $4
+ (i32.load offset=4
+ (get_global $tempDoublePtr)
)
- (i32.const 52)
)
+ (i32.const 52)
)
- (i32.const 2047)
)
- )
- )
- (if
- (i32.eq
- (get_local $5)
(i32.const 2047)
)
- (br $switch)
- (br $switch-default)
)
)
- (i32.store
- (get_local $1)
- (tee_local $2
- (if (result i32)
- (f64.ne
- (get_local $0)
- (f64.const 0)
- )
- (block (result i32)
- (set_local $0
- (call $_frexp
- (f64.mul
- (get_local $0)
- (f64.const 18446744073709551615)
- )
- (get_local $1)
+ (if
+ (i32.eq
+ (get_local $5)
+ (i32.const 2047)
+ )
+ (br $switch)
+ (br $switch-default)
+ )
+ )
+ (i32.store
+ (get_local $1)
+ (tee_local $2
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (f64.const 0)
+ )
+ (block (result i32)
+ (set_local $0
+ (call $_frexp
+ (f64.mul
+ (get_local $0)
+ (f64.const 18446744073709551615)
)
+ (get_local $1)
)
- (i32.add
- (i32.load
- (get_local $1)
- )
- (i32.const -64)
+ )
+ (i32.add
+ (i32.load
+ (get_local $1)
)
+ (i32.const -64)
)
- (i32.const 0)
)
+ (i32.const 0)
)
)
- (br $switch)
)
+ (br $switch)
)
(i32.store
(get_local $1)
diff --git a/test/emcc_hello_world.fromasm.clamp b/test/emcc_hello_world.fromasm.clamp
index 5ee4c0133..68e86ca1a 100644
--- a/test/emcc_hello_world.fromasm.clamp
+++ b/test/emcc_hello_world.fromasm.clamp
@@ -168,70 +168,68 @@
)
(block $switch
(block $switch-default
- (block $switch-case0
- (if
- (tee_local $5
- (tee_local $3
- (i32.and
- (tee_local $3
- (call $_bitshift64Lshr
- (tee_local $2
- (i32.load
- (get_global $tempDoublePtr)
- )
+ (if
+ (tee_local $5
+ (tee_local $3
+ (i32.and
+ (tee_local $3
+ (call $_bitshift64Lshr
+ (tee_local $2
+ (i32.load
+ (get_global $tempDoublePtr)
)
- (tee_local $4
- (i32.load offset=4
- (get_global $tempDoublePtr)
- )
+ )
+ (tee_local $4
+ (i32.load offset=4
+ (get_global $tempDoublePtr)
)
- (i32.const 52)
)
+ (i32.const 52)
)
- (i32.const 2047)
)
- )
- )
- (if
- (i32.eq
- (get_local $5)
(i32.const 2047)
)
- (br $switch)
- (br $switch-default)
)
)
- (i32.store
- (get_local $1)
- (tee_local $2
- (if (result i32)
- (f64.ne
- (get_local $0)
- (f64.const 0)
- )
- (block (result i32)
- (set_local $0
- (call $_frexp
- (f64.mul
- (get_local $0)
- (f64.const 18446744073709551615)
- )
- (get_local $1)
+ (if
+ (i32.eq
+ (get_local $5)
+ (i32.const 2047)
+ )
+ (br $switch)
+ (br $switch-default)
+ )
+ )
+ (i32.store
+ (get_local $1)
+ (tee_local $2
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (f64.const 0)
+ )
+ (block (result i32)
+ (set_local $0
+ (call $_frexp
+ (f64.mul
+ (get_local $0)
+ (f64.const 18446744073709551615)
)
+ (get_local $1)
)
- (i32.add
- (i32.load
- (get_local $1)
- )
- (i32.const -64)
+ )
+ (i32.add
+ (i32.load
+ (get_local $1)
)
+ (i32.const -64)
)
- (i32.const 0)
)
+ (i32.const 0)
)
)
- (br $switch)
)
+ (br $switch)
)
(i32.store
(get_local $1)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 70aea54a9..702b3f170 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -167,70 +167,68 @@
)
(block $switch
(block $switch-default
- (block $switch-case0
- (if
- (tee_local $5
- (tee_local $3
- (i32.and
- (tee_local $3
- (call $_bitshift64Lshr
- (tee_local $2
- (i32.load
- (get_global $tempDoublePtr)
- )
+ (if
+ (tee_local $5
+ (tee_local $3
+ (i32.and
+ (tee_local $3
+ (call $_bitshift64Lshr
+ (tee_local $2
+ (i32.load
+ (get_global $tempDoublePtr)
)
- (tee_local $4
- (i32.load offset=4
- (get_global $tempDoublePtr)
- )
+ )
+ (tee_local $4
+ (i32.load offset=4
+ (get_global $tempDoublePtr)
)
- (i32.const 52)
)
+ (i32.const 52)
)
- (i32.const 2047)
)
- )
- )
- (if
- (i32.eq
- (get_local $5)
(i32.const 2047)
)
- (br $switch)
- (br $switch-default)
)
)
- (i32.store
- (get_local $1)
- (tee_local $2
- (if (result i32)
- (f64.ne
- (get_local $0)
- (f64.const 0)
- )
- (block (result i32)
- (set_local $0
- (call $_frexp
- (f64.mul
- (get_local $0)
- (f64.const 18446744073709551615)
- )
- (get_local $1)
+ (if
+ (i32.eq
+ (get_local $5)
+ (i32.const 2047)
+ )
+ (br $switch)
+ (br $switch-default)
+ )
+ )
+ (i32.store
+ (get_local $1)
+ (tee_local $2
+ (if (result i32)
+ (f64.ne
+ (get_local $0)
+ (f64.const 0)
+ )
+ (block (result i32)
+ (set_local $0
+ (call $_frexp
+ (f64.mul
+ (get_local $0)
+ (f64.const 18446744073709551615)
)
+ (get_local $1)
)
- (i32.add
- (i32.load
- (get_local $1)
- )
- (i32.const -64)
+ )
+ (i32.add
+ (i32.load
+ (get_local $1)
)
+ (i32.const -64)
)
- (i32.const 0)
)
+ (i32.const 0)
)
)
- (br $switch)
)
+ (br $switch)
)
(i32.store
(get_local $1)
diff --git a/test/passes/O.txt b/test/passes/O.txt
index dcf9257c3..3ba18693f 100644
--- a/test/passes/O.txt
+++ b/test/passes/O.txt
@@ -4,18 +4,16 @@
(export "ret" (func $ret))
(export "waka" (func $if-0-unreachable-to-none))
(func $ret (; 0 ;) (; has Stack IR ;) (type $0) (result i32)
- (block $out (result i32)
- (drop
- (call $ret)
- )
- (if
- (call $ret)
- (return
- (i32.const 1)
- )
+ (drop
+ (call $ret)
+ )
+ (if
+ (call $ret)
+ (return
+ (i32.const 1)
)
- (i32.const 999)
)
+ (i32.const 999)
)
(func $if-0-unreachable-to-none (; 1 ;) (; has Stack IR ;) (type $1) (param $0 i64)
(unreachable)
diff --git a/test/passes/flatten_dfo_O3.txt b/test/passes/flatten_dfo_O3.txt
index c0e8a8811..6362c498b 100644
--- a/test/passes/flatten_dfo_O3.txt
+++ b/test/passes/flatten_dfo_O3.txt
@@ -12,12 +12,10 @@
(export "only-dfo" (func $4))
(export "dfo-tee-get" (func $5))
(func $0 (; 0 ;) (; has Stack IR ;) (type $0)
- (loop $label$2
- (block $label$3
- (br_if $label$3
- (i32.load
- (i32.const 3060)
- )
+ (block $label$3
+ (br_if $label$3
+ (i32.load
+ (i32.const 3060)
)
)
)
@@ -27,14 +25,12 @@
(i32.const 0)
)
(func $2 (; 2 ;) (; has Stack IR ;) (type $2) (param $0 i64) (param $1 i32) (result f64)
- (block $label$6
- (loop $label$8
- (br_if $label$8
- (get_local $1)
- )
+ (loop $label$8
+ (br_if $label$8
+ (get_local $1)
)
- (unreachable)
)
+ (unreachable)
)
(func $3 (; 3 ;) (; has Stack IR ;) (type $0)
(i32.store
diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt
index 03eb7b716..952018440 100644
--- a/test/passes/remove-unused-brs.txt
+++ b/test/passes/remove-unused-brs.txt
@@ -469,7 +469,7 @@
(i32.eqz
(i32.const 0)
)
- (block
+ (block $out40
(nop)
(br_if $in39
(i32.const 1)
@@ -614,7 +614,7 @@
(i32.eqz
(i32.const 0)
)
- (block
+ (block $out73
(nop)
(call $loops)
(return)
@@ -897,7 +897,7 @@
(i32.eqz
(i32.const 0)
)
- (block
+ (block $yes
(nop)
(drop
(i32.const 1)
diff --git a/test/passes/remove-unused-brs_shrink-level=1.txt b/test/passes/remove-unused-brs_shrink-level=1.txt
index e07844cf9..619c325eb 100644
--- a/test/passes/remove-unused-brs_shrink-level=1.txt
+++ b/test/passes/remove-unused-brs_shrink-level=1.txt
@@ -109,7 +109,7 @@
(i32.const 0)
)
)
- (block
+ (block $out8
(nop)
(nop)
)
diff --git a/test/passes/remove-unused-brs_shrink-level=1_ignore-implicit-traps.txt b/test/passes/remove-unused-brs_shrink-level=1_ignore-implicit-traps.txt
index 8e865c39d..75b600b3e 100644
--- a/test/passes/remove-unused-brs_shrink-level=1_ignore-implicit-traps.txt
+++ b/test/passes/remove-unused-brs_shrink-level=1_ignore-implicit-traps.txt
@@ -109,7 +109,7 @@
(i32.const 0)
)
)
- (block
+ (block $out8
(nop)
(nop)
)
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 184aaa92d..4a018a780 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -182,15 +182,14 @@
(i32.const 51)
)
)
- (block $switch-case9
- (block $switch-case4
- (br_table $switch-case4 $switch-case9 $switch-case9 $switch-case9 $switch-case9 $switch-case4 $switch-case9 $switch-case4 $switch-case9
- (i32.add
- (get_local $0)
- (i32.const -5)
- )
+ (block $switch-case4
+ (drop
+ (i32.add
+ (get_local $0)
+ (i32.const -5)
)
)
+ (br $switch-case4)
)
(loop $label$continue$L1
(block $label$break$L1
@@ -975,27 +974,25 @@
)
(func $relooperJumpThreading__ZN4game14preloadweaponsEv (; 45 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (param $5 i32) (param $6 i32)
(loop $while-in
- (block $__rjto$1
- (block $__rjti$1
- (if
- (get_local $1)
- (br_if $__rjti$1
- (i32.eqz
- (get_local $2)
- )
+ (block $__rjti$1
+ (if
+ (get_local $1)
+ (br_if $__rjti$1
+ (i32.eqz
+ (get_local $2)
)
- (br_if $__rjti$1
- (i32.eqz
- (get_local $3)
- )
+ )
+ (br_if $__rjti$1
+ (i32.eqz
+ (get_local $3)
)
)
- (br $while-in)
- )
- (i32.store
- (get_local $4)
- (get_local $5)
)
+ (br $while-in)
+ )
+ (i32.store
+ (get_local $4)
+ (get_local $5)
)
(br $while-in)
)
diff --git a/test/unit.fromasm.clamp b/test/unit.fromasm.clamp
index 5ce8dc3e2..fa1965d6a 100644
--- a/test/unit.fromasm.clamp
+++ b/test/unit.fromasm.clamp
@@ -232,15 +232,14 @@
(i32.const 51)
)
)
- (block $switch-case9
- (block $switch-case4
- (br_table $switch-case4 $switch-case9 $switch-case9 $switch-case9 $switch-case9 $switch-case4 $switch-case9 $switch-case4 $switch-case9
- (i32.add
- (get_local $0)
- (i32.const -5)
- )
+ (block $switch-case4
+ (drop
+ (i32.add
+ (get_local $0)
+ (i32.const -5)
)
)
+ (br $switch-case4)
)
(loop $label$continue$L1
(block $label$break$L1
@@ -1025,27 +1024,25 @@
)
(func $relooperJumpThreading__ZN4game14preloadweaponsEv (; 46 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (param $5 i32) (param $6 i32)
(loop $while-in
- (block $__rjto$1
- (block $__rjti$1
- (if
- (get_local $1)
- (br_if $__rjti$1
- (i32.eqz
- (get_local $2)
- )
+ (block $__rjti$1
+ (if
+ (get_local $1)
+ (br_if $__rjti$1
+ (i32.eqz
+ (get_local $2)
)
- (br_if $__rjti$1
- (i32.eqz
- (get_local $3)
- )
+ )
+ (br_if $__rjti$1
+ (i32.eqz
+ (get_local $3)
)
)
- (br $while-in)
- )
- (i32.store
- (get_local $4)
- (get_local $5)
)
+ (br $while-in)
+ )
+ (i32.store
+ (get_local $4)
+ (get_local $5)
)
(br $while-in)
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 9ca992073..7c581ba3e 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -178,15 +178,14 @@
(i32.const 51)
)
)
- (block $switch-case9
- (block $switch-case4
- (br_table $switch-case4 $switch-case9 $switch-case9 $switch-case9 $switch-case9 $switch-case4 $switch-case9 $switch-case4 $switch-case9
- (i32.add
- (get_local $0)
- (i32.const -5)
- )
+ (block $switch-case4
+ (drop
+ (i32.add
+ (get_local $0)
+ (i32.const -5)
)
)
+ (br $switch-case4)
)
(loop $label$continue$L1
(block $label$break$L1
@@ -974,27 +973,25 @@
)
(func $relooperJumpThreading__ZN4game14preloadweaponsEv (; 44 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (param $5 i32) (param $6 i32)
(loop $while-in
- (block $__rjto$1
- (block $__rjti$1
- (if
- (get_local $1)
- (br_if $__rjti$1
- (i32.eqz
- (get_local $2)
- )
+ (block $__rjti$1
+ (if
+ (get_local $1)
+ (br_if $__rjti$1
+ (i32.eqz
+ (get_local $2)
)
- (br_if $__rjti$1
- (i32.eqz
- (get_local $3)
- )
+ )
+ (br_if $__rjti$1
+ (i32.eqz
+ (get_local $3)
)
)
- (br $while-in)
- )
- (i32.store
- (get_local $4)
- (get_local $5)
)
+ (br $while-in)
+ )
+ (i32.store
+ (get_local $4)
+ (get_local $5)
)
(br $while-in)
)