summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/Vacuum.cpp17
-rw-r--r--test/emcc_hello_world.fromasm20
-rw-r--r--test/emcc_hello_world.fromasm.imprecise20
-rw-r--r--test/passes/vacuum.txt7
-rw-r--r--test/passes/vacuum.wast10
-rw-r--r--test/unit.fromasm4
-rw-r--r--test/unit.fromasm.imprecise4
7 files changed, 31 insertions, 51 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 863d78f14..ed868f2f9 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -32,14 +32,25 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum, Visitor<Vacuum>>> {
int skip = 0;
auto& list = curr->list;
size_t size = list.size();
+ bool needResize = false;
for (size_t z = 0; z < size; z++) {
if (list[z]->is<Nop>()) {
skip++;
- } else if (skip > 0) {
- list[z - skip] = list[z];
+ needResize = true;
+ } else {
+ if (skip > 0) {
+ list[z - skip] = list[z];
+ }
+ // if this is an unconditional br, the rest is dead code
+ Break* br = list[z - skip]->dynCast<Break>();
+ if (br && !br->condition) {
+ list.resize(z - skip + 1);
+ needResize = false;
+ break;
+ }
}
}
- if (skip > 0) {
+ if (needResize) {
list.resize(size - skip);
}
if (!curr->name.is()) {
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 2d8457313..387da4310 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -3963,7 +3963,6 @@
(i32.const 9)
)
(br $label$break$L9)
- (br $switch$2)
)
(set_local $$incdec$ptr169276$lcssa
(get_local $$incdec$ptr169274)
@@ -3972,7 +3971,6 @@
(get_local $$incdec$ptr169274)
)
(br $label$break$L9)
- (br $switch$2)
)
)
)
@@ -5394,7 +5392,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(i32.load
@@ -5415,7 +5412,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(set_local $$76
@@ -5451,7 +5447,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store16
(i32.load
@@ -5475,7 +5470,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store8
(i32.load
@@ -5499,7 +5493,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(i32.load
@@ -5520,7 +5513,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(set_local $$86
@@ -5556,7 +5548,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(set_local $$cnt$0
(get_local $$cnt$1)
@@ -9328,7 +9319,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$24)
)
(set_local $$a$2
(get_local $$incdec$ptr169275)
@@ -10440,7 +10430,6 @@
(get_local $$6)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$13
(i32.load
@@ -10499,7 +10488,6 @@
)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$26
(i32.load
@@ -10549,7 +10537,6 @@
(i32.const 0)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$39
(i32.load
@@ -10606,7 +10593,6 @@
(get_local $$42)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$53
(i32.load
@@ -10679,7 +10665,6 @@
(get_local $$56)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$67
(i32.load
@@ -10732,7 +10717,6 @@
(i32.const 0)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$78
(i32.load
@@ -10805,7 +10789,6 @@
(get_local $$81)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$92
(i32.load
@@ -10858,7 +10841,6 @@
(i32.const 0)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$103
(f64.load
@@ -10902,7 +10884,6 @@
(get_local $$103)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$110
(f64.load
@@ -10946,7 +10927,6 @@
(get_local $$110)
)
(br $label$break$L1)
- (br $switch$3)
)
(br $label$break$L1)
)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 71a0412b7..6fcffbf53 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -3961,7 +3961,6 @@
(i32.const 9)
)
(br $label$break$L9)
- (br $switch$2)
)
(set_local $$incdec$ptr169276$lcssa
(get_local $$incdec$ptr169274)
@@ -3970,7 +3969,6 @@
(get_local $$incdec$ptr169274)
)
(br $label$break$L9)
- (br $switch$2)
)
)
)
@@ -5392,7 +5390,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(i32.load
@@ -5413,7 +5410,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(set_local $$76
@@ -5449,7 +5445,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store16
(i32.load
@@ -5473,7 +5468,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store8
(i32.load
@@ -5497,7 +5491,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(i32.load
@@ -5518,7 +5511,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(i32.store
(set_local $$86
@@ -5554,7 +5546,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$25)
)
(set_local $$cnt$0
(get_local $$cnt$1)
@@ -9326,7 +9317,6 @@
(get_local $$l10n$3)
)
(br $label$continue$L1)
- (br $switch$24)
)
(set_local $$a$2
(get_local $$incdec$ptr169275)
@@ -10438,7 +10428,6 @@
(get_local $$6)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$13
(i32.load
@@ -10497,7 +10486,6 @@
)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$26
(i32.load
@@ -10547,7 +10535,6 @@
(i32.const 0)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$39
(i32.load
@@ -10604,7 +10591,6 @@
(get_local $$42)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$53
(i32.load
@@ -10677,7 +10663,6 @@
(get_local $$56)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$67
(i32.load
@@ -10730,7 +10715,6 @@
(i32.const 0)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$78
(i32.load
@@ -10803,7 +10787,6 @@
(get_local $$81)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$92
(i32.load
@@ -10856,7 +10839,6 @@
(i32.const 0)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$103
(f64.load
@@ -10900,7 +10882,6 @@
(get_local $$103)
)
(br $label$break$L1)
- (br $switch$3)
)
(set_local $$110
(f64.load
@@ -10944,7 +10925,6 @@
(get_local $$110)
)
(br $label$break$L1)
- (br $switch$3)
)
(br $label$break$L1)
)
diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt
index bb76b2d82..a6c7f22f0 100644
--- a/test/passes/vacuum.txt
+++ b/test/passes/vacuum.txt
@@ -4,5 +4,12 @@
(i32.const 50)
(i32.const 51)
(i32.const 52)
+ (block $waka1
+ (i32.const 53)
+ (br $waka1)
+ )
+ (block $waka2
+ (br $waka2)
+ )
)
)
diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast
index 24dc32bcb..dda86804e 100644
--- a/test/passes/vacuum.wast
+++ b/test/passes/vacuum.wast
@@ -7,6 +7,16 @@
(nop)
(nop)
(i32.const 52)
+ (block $waka1
+ (i32.const 53)
+ (br $waka1)
+ (i32.const 54)
+ )
+ (block $waka2
+ (nop)
+ (br $waka2)
+ (i32.const 56)
+ )
)
)
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 0b43f14fc..412bfcace 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -222,13 +222,11 @@
)
(loop $while-out$10 $while-in$11
(br $while-out$10)
- (br $while-in$11)
)
(br $label$break$Lout)
)
(loop $while-out$13 $while-in$14
(br $label$break$Lout)
- (br $while-in$14)
)
(br $label$break$Lout)
)
@@ -249,13 +247,11 @@
)
)
(br $label$break$L1)
- (br $switch$17)
)
(i32.const 1)
(br $switch$17)
)
(br $label$break$L3)
- (br $switch$17)
)
(br $label$break$L1)
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index f5ba55d90..363131ff3 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -216,13 +216,11 @@
)
(loop $while-out$10 $while-in$11
(br $while-out$10)
- (br $while-in$11)
)
(br $label$break$Lout)
)
(loop $while-out$13 $while-in$14
(br $label$break$Lout)
- (br $while-in$14)
)
(br $label$break$Lout)
)
@@ -243,13 +241,11 @@
)
)
(br $label$break$L1)
- (br $switch$17)
)
(i32.const 1)
(br $switch$17)
)
(br $label$break$L3)
- (br $switch$17)
)
(br $label$break$L1)
)