summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/Flatten.cpp5
-rw-r--r--test/passes/flatten.bin.txt1
-rw-r--r--test/passes/flatten_all-features.txt84
-rw-r--r--test/passes/flatten_all-features.wast14
-rw-r--r--test/passes/flatten_i64-to-i32-lowering.txt4
-rw-r--r--test/passes/flatten_local-cse_all-features.txt5
-rw-r--r--test/passes/flatten_rereloop.txt18
-rw-r--r--test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt77
-rw-r--r--test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt77
9 files changed, 237 insertions, 48 deletions
diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp
index 9139d5dca..55ee00936 100644
--- a/src/passes/Flatten.cpp
+++ b/src/passes/Flatten.cpp
@@ -62,9 +62,8 @@ struct Flatten
std::vector<Expression*> ourPreludes;
Builder builder(*getModule());
- // Nothing to do for constants, nop, and unreachable
- if (Properties::isConstantExpression(curr) || curr->is<Nop>() ||
- curr->is<Unreachable>()) {
+ // Nothing to do for constants and nop.
+ if (Properties::isConstantExpression(curr) || curr->is<Nop>()) {
return;
}
diff --git a/test/passes/flatten.bin.txt b/test/passes/flatten.bin.txt
index 35b2717e9..bc4d93cb7 100644
--- a/test/passes/flatten.bin.txt
+++ b/test/passes/flatten.bin.txt
@@ -103,6 +103,7 @@
(block $label$1
(nop)
(unreachable)
+ (unreachable)
)
(unreachable)
)
diff --git a/test/passes/flatten_all-features.txt b/test/passes/flatten_all-features.txt
index ef36e3333..c633eccc8 100644
--- a/test/passes/flatten_all-features.txt
+++ b/test/passes/flatten_all-features.txt
@@ -540,10 +540,14 @@
)
(if
(local.get $0)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
(block
(block $label$3
(unreachable)
+ (unreachable)
)
(local.set $2
(local.get $1)
@@ -651,6 +655,7 @@
(local $0 i32)
(local $1 i32)
(block $label$1
+ (unreachable)
(local.set $0
(i32.const 1)
)
@@ -676,6 +681,7 @@
(func $a19 (result f32)
(block $label$0
(block $label$1
+ (unreachable)
(return
(f32.const 4289944320)
)
@@ -727,6 +733,7 @@
(block
(block $out1
(unreachable)
+ (unreachable)
(drop
(i32.const 0)
)
@@ -773,6 +780,7 @@
(block
(block $out8
(unreachable)
+ (unreachable)
(drop
(i32.const 0)
)
@@ -782,6 +790,7 @@
(block
(block $out9
(unreachable)
+ (unreachable)
(drop
(i32.const 0)
)
@@ -803,10 +812,12 @@
(block $out11
(unreachable)
(unreachable)
+ (unreachable)
(drop
(i32.const 0)
)
(unreachable)
+ (unreachable)
)
(local.set $2
(local.get $1)
@@ -822,10 +833,12 @@
(block $out13
(unreachable)
(unreachable)
+ (unreachable)
(drop
(i32.const 0)
)
(unreachable)
+ (unreachable)
)
(local.set $4
(local.get $3)
@@ -841,10 +854,13 @@
(block $out15
(unreachable)
(unreachable)
+ (unreachable)
+ (unreachable)
(drop
(i32.const 0)
)
(unreachable)
+ (unreachable)
)
(local.set $6
(local.get $5)
@@ -861,6 +877,7 @@
)
)
(unreachable)
+ (unreachable)
)
(if
(i32.const 0)
@@ -873,6 +890,7 @@
)
)
(unreachable)
+ (unreachable)
)
(unreachable)
(drop
@@ -890,6 +908,7 @@
(unreachable)
)
(unreachable)
+ (unreachable)
)
(block $out22
(block $in23
@@ -899,6 +918,7 @@
(unreachable)
)
(unreachable)
+ (unreachable)
)
(if
(i32.const 0)
@@ -912,6 +932,7 @@
(unreachable)
)
(unreachable)
+ (unreachable)
)
(unreachable)
(drop
@@ -932,11 +953,14 @@
(i32.const 42)
)
(unreachable)
+ (unreachable)
+ (unreachable)
(return
(unreachable)
)
(unreachable)
(unreachable)
+ (unreachable)
(return)
(unreachable)
)
@@ -948,6 +972,7 @@
(block
(loop $loop-in18
(unreachable)
+ (unreachable)
)
(unreachable)
)
@@ -959,6 +984,7 @@
(i32.const 1)
)
(unreachable)
+ (unreachable)
)
(unreachable)
)
@@ -974,6 +1000,7 @@
(i32.const 1)
)
(unreachable)
+ (unreachable)
)
(unreachable)
)
@@ -988,6 +1015,7 @@
(if
(i32.const 1)
(block
+ (unreachable)
(call $call-me
(i32.const 123)
(unreachable)
@@ -998,6 +1026,7 @@
(if
(i32.const 2)
(block
+ (unreachable)
(call $call-me
(unreachable)
(i32.const 0)
@@ -1008,6 +1037,8 @@
(if
(i32.const 3)
(block
+ (unreachable)
+ (unreachable)
(call $call-me
(unreachable)
(unreachable)
@@ -1018,6 +1049,7 @@
(if
(i32.const -1)
(block
+ (unreachable)
(call_indirect (type $i32_i32_=>_none)
(i32.const 123)
(i32.const 456)
@@ -1029,6 +1061,7 @@
(if
(i32.const -2)
(block
+ (unreachable)
(call_indirect (type $i32_i32_=>_none)
(i32.const 139)
(unreachable)
@@ -1040,6 +1073,8 @@
(if
(i32.const -3)
(block
+ (unreachable)
+ (unreachable)
(call_indirect (type $i32_i32_=>_none)
(i32.const 246)
(unreachable)
@@ -1051,6 +1086,9 @@
(if
(i32.const -4)
(block
+ (unreachable)
+ (unreachable)
+ (unreachable)
(call_indirect (type $i32_i32_=>_none)
(unreachable)
(unreachable)
@@ -1064,11 +1102,13 @@
(block
(unreachable)
(unreachable)
+ (unreachable)
)
)
(if
(i32.const 22)
(block
+ (unreachable)
(i32.load
(unreachable)
)
@@ -1081,6 +1121,7 @@
(if
(i32.const 33)
(block
+ (unreachable)
(i32.store
(i32.const 0)
(unreachable)
@@ -1091,6 +1132,7 @@
(if
(i32.const 44)
(block
+ (unreachable)
(i32.store
(unreachable)
(i32.const 0)
@@ -1101,6 +1143,8 @@
(if
(i32.const 55)
(block
+ (unreachable)
+ (unreachable)
(i32.store
(unreachable)
(unreachable)
@@ -1111,6 +1155,7 @@
(if
(i32.const 66)
(block
+ (unreachable)
(i32.eqz
(unreachable)
)
@@ -1123,6 +1168,7 @@
(if
(i32.const 77)
(block
+ (unreachable)
(i32.add
(unreachable)
(i32.const 0)
@@ -1136,6 +1182,7 @@
(if
(i32.const 88)
(block
+ (unreachable)
(i32.add
(i32.const 0)
(unreachable)
@@ -1149,6 +1196,8 @@
(if
(i32.const 99)
(block
+ (unreachable)
+ (unreachable)
(i32.add
(unreachable)
(unreachable)
@@ -1159,6 +1208,7 @@
(if
(i32.const 100)
(block
+ (unreachable)
(select
(i32.const 123)
(i32.const 456)
@@ -1173,6 +1223,7 @@
(if
(i32.const 101)
(block
+ (unreachable)
(select
(i32.const 123)
(unreachable)
@@ -1187,6 +1238,7 @@
(if
(i32.const 102)
(block
+ (unreachable)
(select
(unreachable)
(i32.const 123)
@@ -1205,6 +1257,7 @@
(func $killer
(block
(unreachable)
+ (unreachable)
(drop
(i32.const 1000)
)
@@ -1290,6 +1343,7 @@
(local $0 i32)
(block
(unreachable)
+ (unreachable)
(local.set $0
(global.get $x)
)
@@ -1353,11 +1407,13 @@
(block $label$0
(block $label$3
(nop)
+ (unreachable)
(br_table $label$3
(unreachable)
)
(unreachable)
(unreachable)
+ (unreachable)
)
(local.set $0
(i32.const 19)
@@ -1376,11 +1432,13 @@
(block $label$0
(block $label$2
(nop)
+ (unreachable)
(br_if $label$2
(unreachable)
)
(unreachable)
(unreachable)
+ (unreachable)
)
(local.set $0
(i32.const 19)
@@ -1425,6 +1483,7 @@
(local $5 i32)
(block $label$0
(block $label$1
+ (unreachable)
(local.set $1
(i32.const 4104)
)
@@ -1538,6 +1597,7 @@
(local.set $13
(local.get $12)
)
+ (unreachable)
(i64.mul
(local.get $13)
(unreachable)
@@ -1897,6 +1957,7 @@
(unreachable)
)
(unreachable)
+ (unreachable)
(i32.add
(i32.const 1)
(unreachable)
@@ -2196,6 +2257,7 @@
)
(func $switch-unreachable
(block $label$3
+ (unreachable)
(br_table $label$3
(unreachable)
)
@@ -2278,6 +2340,7 @@
(local.get $2)
)
(unreachable)
+ (unreachable)
(drop
(unreachable)
)
@@ -2361,3 +2424,22 @@
)
)
)
+(module
+ (type $i64_f32_=>_none (func (param i64 f32)))
+ (type $none_=>_i32 (func (result i32)))
+ (export "test" (func $1))
+ (func $0 (param $0 i64) (param $1 f32)
+ (nop)
+ )
+ (func $1 (result i32)
+ (unreachable)
+ (return
+ (i32.const -111)
+ )
+ (call $0
+ (unreachable)
+ (unreachable)
+ )
+ (unreachable)
+ )
+)
diff --git a/test/passes/flatten_all-features.wast b/test/passes/flatten_all-features.wast
index fe8629e73..461ce6170 100644
--- a/test/passes/flatten_all-features.wast
+++ b/test/passes/flatten_all-features.wast
@@ -1040,3 +1040,17 @@
)
)
)
+(module
+ (func $0 (param $0 i64) (param $1 f32)
+ (nop)
+ )
+ (func "test" (result i32)
+ (call $0
+ (unreachable) ;; the unreachable should be handled properly, and not be
+ ;; reordered with the return
+ (return
+ (i32.const -111)
+ )
+ )
+ )
+)
diff --git a/test/passes/flatten_i64-to-i32-lowering.txt b/test/passes/flatten_i64-to-i32-lowering.txt
index 1857a9372..b115ff619 100644
--- a/test/passes/flatten_i64-to-i32-lowering.txt
+++ b/test/passes/flatten_i64-to-i32-lowering.txt
@@ -83,6 +83,7 @@
)
(func $unreachable-select-i64 (result i32)
(local $i64toi32_i32$0 i32)
+ (unreachable)
(block
(drop
(block (result i32)
@@ -101,6 +102,7 @@
)
(func $unreachable-select-i64-b (result i32)
(local $i64toi32_i32$0 i32)
+ (unreachable)
(block
(unreachable)
(drop
@@ -120,6 +122,7 @@
(func $unreachable-select-i64-c (result i32)
(local $i64toi32_i32$0 i32)
(local $i64toi32_i32$1 i32)
+ (unreachable)
(block
(drop
(block (result i32)
@@ -463,6 +466,7 @@
(local $i64toi32_i32$0 i32)
(block $label$1
(unreachable)
+ (unreachable)
)
(block
(local.set $1
diff --git a/test/passes/flatten_local-cse_all-features.txt b/test/passes/flatten_local-cse_all-features.txt
index a362d989b..c80611abe 100644
--- a/test/passes/flatten_local-cse_all-features.txt
+++ b/test/passes/flatten_local-cse_all-features.txt
@@ -646,7 +646,10 @@
)
(if
(local.get $2)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(local.set $3
diff --git a/test/passes/flatten_rereloop.txt b/test/passes/flatten_rereloop.txt
index 6558263b7..c0b406816 100644
--- a/test/passes/flatten_rereloop.txt
+++ b/test/passes/flatten_rereloop.txt
@@ -517,7 +517,7 @@
(local $8 i32)
(local $9 i32)
(local $10 i32)
- (block $block$18$break
+ (block $block$21$break
(block
(local.set $4
(local.get $x)
@@ -537,11 +537,11 @@
(br $shape$2$continue)
)
)
- (br $block$18$break)
+ (br $block$21$break)
)
)
(block
- (block $block$21$break
+ (block $block$24$break
(loop $shape$4$continue
(block
(call $trivial)
@@ -558,7 +558,7 @@
(if
(local.get $7)
(br $shape$4$continue)
- (br $block$21$break)
+ (br $block$24$break)
)
)
)
@@ -972,7 +972,7 @@
)
)
(block
- (block $block$8$break
+ (block $block$9$break
(block
(call $switch
(i32.const 1)
@@ -989,13 +989,13 @@
)
(block $switch$3$leave
(block $switch$3$default
- (block $switch$3$case$8
- (br_table $switch$3$case$8 $switch$3$case$8 $switch$3$case$8 $switch$3$default
+ (block $switch$3$case$9
+ (br_table $switch$3$case$9 $switch$3$case$9 $switch$3$case$9 $switch$3$default
(local.get $6)
)
)
(block
- (br $block$8$break)
+ (br $block$9$break)
)
)
(block
@@ -1004,7 +1004,7 @@
(i32.const 2)
)
(block
- (br $block$8$break)
+ (br $block$9$break)
)
)
)
diff --git a/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt b/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt
index e7f61aa21..175aab66a 100644
--- a/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt
+++ b/test/passes/flatten_simplify-locals-nonesting_souperify-single-use_enable-threads.txt
@@ -1567,7 +1567,10 @@ infer %4
)
(unreachable)
)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(unreachable)
@@ -1756,15 +1759,18 @@ infer %4
(func $various-conditions-4 (param $x i32)
(local $1 i32)
(local $2 i32)
- (if
+ (block
(unreachable)
- (block
- (nop)
- (nop)
- (local.set $x
- (i32.add
- (local.get $x)
- (i32.const 3)
+ (if
+ (unreachable)
+ (block
+ (nop)
+ (nop)
+ (local.set $x
+ (i32.add
+ (local.get $x)
+ (i32.const 3)
+ )
)
)
)
@@ -2393,6 +2399,7 @@ infer %4
(i32.const 1)
)
(unreachable)
+ (unreachable)
)
(unreachable)
)
@@ -2609,6 +2616,7 @@ infer %4
(local.get $1)
)
(unreachable)
+ (unreachable)
)
(i32.store16
(i32.const 0)
@@ -2620,6 +2628,7 @@ infer %4
(local $3 i32)
(block $block
(unreachable)
+ (unreachable)
(block
(nop)
(if
@@ -2664,6 +2673,7 @@ infer %4
(unreachable)
)
(unreachable)
+ (unreachable)
)
(br $label$1)
(unreachable)
@@ -2685,6 +2695,7 @@ infer %4
(unreachable)
)
(unreachable)
+ (unreachable)
)
(nop)
(i32.store
@@ -3945,7 +3956,10 @@ infer %4
(block $label$3
(if
(i32.const 0)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
(nop)
(nop)
@@ -3955,7 +3969,10 @@ infer %4
)
(if
(local.get $6)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(nop)
@@ -3998,7 +4015,10 @@ infer %4
(block $label$4
(if
(i32.const 1337)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
(nop)
(nop)
@@ -4030,6 +4050,7 @@ infer %4
(local.get $6)
)
(unreachable)
+ (unreachable)
)
(nop)
(br_if $label$6
@@ -4080,7 +4101,10 @@ infer %4
(nop)
(if
(local.get $var$0)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
(block
(block $block
(block
@@ -4122,6 +4146,7 @@ infer %4
(nop)
(nop)
(unreachable)
+ (unreachable)
)
(nop)
(return
@@ -4286,6 +4311,7 @@ infer %4
(local.get $8)
)
(unreachable)
+ (unreachable)
)
(nop)
(local.set $10
@@ -4311,10 +4337,14 @@ infer %4
)
(if
(local.get $13)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(unreachable)
+ (unreachable)
)
)
)
@@ -4383,6 +4413,7 @@ infer %4
(unreachable)
)
(unreachable)
+ (unreachable)
)
(br $label$1)
(unreachable)
@@ -4409,6 +4440,7 @@ infer %4
)
)
(unreachable)
+ (unreachable)
)
(nop)
(i32.store offset=176
@@ -4468,7 +4500,10 @@ infer %4
)
(if
(local.get $8)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(func $zext-numGets-hasAnotherUse (param $var$0 i32) (param $var$1 i32)
@@ -4526,7 +4561,10 @@ infer %4
)
(if
(local.get $11)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(func $flipped-needs-right-origin (param $var$0 i32) (result i32)
@@ -4567,7 +4605,10 @@ infer %4
)
(if
(local.get $5)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(nop)
@@ -4613,6 +4654,7 @@ infer %4
(local.get $7)
)
(unreachable)
+ (unreachable)
)
(nop)
(return
@@ -4723,6 +4765,7 @@ infer %4
(i32.const 64)
)
(unreachable)
+ (unreachable)
)
(nop)
(return
diff --git a/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt b/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt
index d18eff957..284274ff1 100644
--- a/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt
+++ b/test/passes/flatten_simplify-locals-nonesting_souperify_enable-threads.txt
@@ -1608,7 +1608,10 @@ infer %4
)
(unreachable)
)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(unreachable)
@@ -1858,15 +1861,18 @@ infer %4
(func $various-conditions-4 (param $x i32)
(local $1 i32)
(local $2 i32)
- (if
+ (block
(unreachable)
- (block
- (nop)
- (nop)
- (local.set $x
- (i32.add
- (local.get $x)
- (i32.const 3)
+ (if
+ (unreachable)
+ (block
+ (nop)
+ (nop)
+ (local.set $x
+ (i32.add
+ (local.get $x)
+ (i32.const 3)
+ )
)
)
)
@@ -2495,6 +2501,7 @@ infer %4
(i32.const 1)
)
(unreachable)
+ (unreachable)
)
(unreachable)
)
@@ -2711,6 +2718,7 @@ infer %4
(local.get $1)
)
(unreachable)
+ (unreachable)
)
(i32.store16
(i32.const 0)
@@ -2722,6 +2730,7 @@ infer %4
(local $3 i32)
(block $block
(unreachable)
+ (unreachable)
(block
(nop)
(if
@@ -2766,6 +2775,7 @@ infer %4
(unreachable)
)
(unreachable)
+ (unreachable)
)
(br $label$1)
(unreachable)
@@ -2787,6 +2797,7 @@ infer %4
(unreachable)
)
(unreachable)
+ (unreachable)
)
(nop)
(i32.store
@@ -4047,7 +4058,10 @@ infer %4
(block $label$3
(if
(i32.const 0)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
(nop)
(nop)
@@ -4057,7 +4071,10 @@ infer %4
)
(if
(local.get $6)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(nop)
@@ -4100,7 +4117,10 @@ infer %4
(block $label$4
(if
(i32.const 1337)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
(nop)
(nop)
@@ -4132,6 +4152,7 @@ infer %4
(local.get $6)
)
(unreachable)
+ (unreachable)
)
(nop)
(br_if $label$6
@@ -4182,7 +4203,10 @@ infer %4
(nop)
(if
(local.get $var$0)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
(block
(block $block
(block
@@ -4224,6 +4248,7 @@ infer %4
(nop)
(nop)
(unreachable)
+ (unreachable)
)
(nop)
(return
@@ -4388,6 +4413,7 @@ infer %4
(local.get $8)
)
(unreachable)
+ (unreachable)
)
(nop)
(local.set $10
@@ -4413,10 +4439,14 @@ infer %4
)
(if
(local.get $13)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(unreachable)
+ (unreachable)
)
)
)
@@ -4485,6 +4515,7 @@ infer %4
(unreachable)
)
(unreachable)
+ (unreachable)
)
(br $label$1)
(unreachable)
@@ -4511,6 +4542,7 @@ infer %4
)
)
(unreachable)
+ (unreachable)
)
(nop)
(i32.store offset=176
@@ -4570,7 +4602,10 @@ infer %4
)
(if
(local.get $8)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(func $zext-numGets-hasAnotherUse (param $var$0 i32) (param $var$1 i32)
@@ -4628,7 +4663,10 @@ infer %4
)
(if
(local.get $11)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(func $flipped-needs-right-origin (param $var$0 i32) (result i32)
@@ -4669,7 +4707,10 @@ infer %4
)
(if
(local.get $5)
- (unreachable)
+ (block
+ (unreachable)
+ (unreachable)
+ )
)
)
(nop)
@@ -4715,6 +4756,7 @@ infer %4
(local.get $7)
)
(unreachable)
+ (unreachable)
)
(nop)
(return
@@ -4825,6 +4867,7 @@ infer %4
(i32.const 64)
)
(unreachable)
+ (unreachable)
)
(nop)
(return