summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/Vacuum.cpp4
-rw-r--r--test/emcc_hello_world.fromasm66
-rw-r--r--test/emcc_hello_world.fromasm.clamp66
-rw-r--r--test/emcc_hello_world.fromasm.imprecise56
-rw-r--r--test/passes/vacuum.txt13
-rw-r--r--test/passes/vacuum.wast16
-rw-r--r--test/passes/vacuum_ignore-implicit-traps.txt10
-rw-r--r--test/passes/vacuum_ignore-implicit-traps.wast19
-rw-r--r--test/wasm-only.fromasm131
-rw-r--r--test/wasm-only.fromasm.clamp131
10 files changed, 449 insertions, 63 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index b58bea4b3..70230e502 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -73,7 +73,9 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
case Expression::Id::UnreachableId: return curr; // always needed
case Expression::Id::LoadId: {
- if (!resultUsed) {
+ // it is ok to remove a load if the result is not used, and it has no
+ // side effects (the load itself may trap, if we are not ignoring such things)
+ if (!resultUsed && !EffectAnalyzer(getPassOptions(), curr).hasSideEffects()) {
return curr->cast<Load>()->ptr;
}
return curr;
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index a7ad859f6..10d0f69e9 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -2819,17 +2819,21 @@
)
(i32.const 10)
)
- (set_local $6
- (i32.add
- (get_local $3)
- (i32.shl
+ (drop
+ (i32.load offset=4
+ (tee_local $6
(i32.add
- (i32.load8_s
- (get_local $6)
+ (get_local $3)
+ (i32.shl
+ (i32.add
+ (i32.load8_s
+ (get_local $6)
+ )
+ (i32.const -48)
+ )
+ (i32.const 3)
)
- (i32.const -48)
)
- (i32.const 3)
)
)
)
@@ -3157,17 +3161,21 @@
)
(i32.const 10)
)
- (set_local $6
- (i32.add
- (get_local $3)
- (i32.shl
+ (drop
+ (i32.load offset=4
+ (tee_local $6
(i32.add
- (i32.load8_s
- (get_local $6)
+ (get_local $3)
+ (i32.shl
+ (i32.add
+ (i32.load8_s
+ (get_local $6)
+ )
+ (i32.const -48)
+ )
+ (i32.const 3)
)
- (i32.const -48)
)
- (i32.const 3)
)
)
)
@@ -3885,8 +3893,12 @@
)
(br $__rjti$4)
)
- (set_local $5
- (get_local $19)
+ (drop
+ (i32.load offset=4
+ (tee_local $5
+ (get_local $19)
+ )
+ )
)
(i32.store8
(get_local $40)
@@ -3935,8 +3947,12 @@
)
(br $__rjti$5)
)
- (set_local $5
- (get_local $19)
+ (drop
+ (i32.load offset=4
+ (tee_local $5
+ (get_local $19)
+ )
+ )
)
(i32.store
(get_local $41)
@@ -3993,6 +4009,11 @@
(get_global $tempDoublePtr)
(get_local $15)
)
+ (drop
+ (i32.load
+ (get_global $tempDoublePtr)
+ )
+ )
(set_local $31
(if (result i32)
(i32.lt_s
@@ -4045,6 +4066,11 @@
(get_global $tempDoublePtr)
(get_local $15)
)
+ (drop
+ (i32.load
+ (get_global $tempDoublePtr)
+ )
+ )
(set_local $7
(block $do-once49 (result i32)
(if (result i32)
diff --git a/test/emcc_hello_world.fromasm.clamp b/test/emcc_hello_world.fromasm.clamp
index 80a1f92b2..af2b8a467 100644
--- a/test/emcc_hello_world.fromasm.clamp
+++ b/test/emcc_hello_world.fromasm.clamp
@@ -2843,17 +2843,21 @@
)
(i32.const 10)
)
- (set_local $6
- (i32.add
- (get_local $3)
- (i32.shl
+ (drop
+ (i32.load offset=4
+ (tee_local $6
(i32.add
- (i32.load8_s
- (get_local $6)
+ (get_local $3)
+ (i32.shl
+ (i32.add
+ (i32.load8_s
+ (get_local $6)
+ )
+ (i32.const -48)
+ )
+ (i32.const 3)
)
- (i32.const -48)
)
- (i32.const 3)
)
)
)
@@ -3181,17 +3185,21 @@
)
(i32.const 10)
)
- (set_local $6
- (i32.add
- (get_local $3)
- (i32.shl
+ (drop
+ (i32.load offset=4
+ (tee_local $6
(i32.add
- (i32.load8_s
- (get_local $6)
+ (get_local $3)
+ (i32.shl
+ (i32.add
+ (i32.load8_s
+ (get_local $6)
+ )
+ (i32.const -48)
+ )
+ (i32.const 3)
)
- (i32.const -48)
)
- (i32.const 3)
)
)
)
@@ -3909,8 +3917,12 @@
)
(br $__rjti$4)
)
- (set_local $5
- (get_local $19)
+ (drop
+ (i32.load offset=4
+ (tee_local $5
+ (get_local $19)
+ )
+ )
)
(i32.store8
(get_local $40)
@@ -3959,8 +3971,12 @@
)
(br $__rjti$5)
)
- (set_local $5
- (get_local $19)
+ (drop
+ (i32.load offset=4
+ (tee_local $5
+ (get_local $19)
+ )
+ )
)
(i32.store
(get_local $41)
@@ -4017,6 +4033,11 @@
(get_global $tempDoublePtr)
(get_local $15)
)
+ (drop
+ (i32.load
+ (get_global $tempDoublePtr)
+ )
+ )
(set_local $31
(if (result i32)
(i32.lt_s
@@ -4069,6 +4090,11 @@
(get_global $tempDoublePtr)
(get_local $15)
)
+ (drop
+ (i32.load
+ (get_global $tempDoublePtr)
+ )
+ )
(set_local $7
(block $do-once49 (result i32)
(if (result i32)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 65fda0e77..96344b09d 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -2763,17 +2763,21 @@
)
(i32.const 10)
)
- (set_local $6
- (i32.add
- (get_local $3)
- (i32.shl
+ (drop
+ (i32.load offset=4
+ (tee_local $6
(i32.add
- (i32.load8_s
- (get_local $6)
+ (get_local $3)
+ (i32.shl
+ (i32.add
+ (i32.load8_s
+ (get_local $6)
+ )
+ (i32.const -48)
+ )
+ (i32.const 3)
)
- (i32.const -48)
)
- (i32.const 3)
)
)
)
@@ -3102,17 +3106,21 @@
)
(i32.const 10)
)
- (set_local $6
- (i32.add
- (get_local $3)
- (i32.shl
+ (drop
+ (i32.load offset=4
+ (tee_local $6
(i32.add
- (i32.load8_s
- (get_local $6)
+ (get_local $3)
+ (i32.shl
+ (i32.add
+ (i32.load8_s
+ (get_local $6)
+ )
+ (i32.const -48)
+ )
+ (i32.const 3)
)
- (i32.const -48)
)
- (i32.const 3)
)
)
)
@@ -3830,8 +3838,12 @@
)
(br $__rjti$4)
)
- (set_local $5
- (get_local $19)
+ (drop
+ (i32.load offset=4
+ (tee_local $5
+ (get_local $19)
+ )
+ )
)
(i32.store8
(get_local $40)
@@ -3880,8 +3892,12 @@
)
(br $__rjti$5)
)
- (set_local $5
- (get_local $19)
+ (drop
+ (i32.load offset=4
+ (tee_local $5
+ (get_local $19)
+ )
+ )
)
(i32.store
(get_local $41)
diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt
index cb85838ac..f17607734 100644
--- a/test/passes/vacuum.txt
+++ b/test/passes/vacuum.txt
@@ -247,4 +247,17 @@
)
(unreachable)
)
+ (func $load-may-have-side-effects (type $3) (result i32)
+ (i64.ge_s
+ (block $block (result i64)
+ (drop
+ (i64.load32_s
+ (i32.const 678585719)
+ )
+ )
+ (i64.const 2912825531628789796)
+ )
+ (i64.const 0)
+ )
+ )
)
diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast
index 2b8486384..65e528621 100644
--- a/test/passes/vacuum.wast
+++ b/test/passes/vacuum.wast
@@ -564,4 +564,20 @@
)
(unreachable)
)
+ (func $load-may-have-side-effects (result i32)
+ (i64.ge_s
+ (block (result i64)
+ (drop
+ (i64.eq
+ (i64.load32_s
+ (i32.const 678585719)
+ )
+ (i64.const 8097879367757079605)
+ )
+ )
+ (i64.const 2912825531628789796)
+ )
+ (i64.const 0)
+ )
+ )
)
diff --git a/test/passes/vacuum_ignore-implicit-traps.txt b/test/passes/vacuum_ignore-implicit-traps.txt
new file mode 100644
index 000000000..040a3dc1a
--- /dev/null
+++ b/test/passes/vacuum_ignore-implicit-traps.txt
@@ -0,0 +1,10 @@
+(module
+ (type $0 (func (result i32)))
+ (memory $0 0)
+ (func $load-would-normally-have-side-effects (type $0) (result i32)
+ (i64.ge_s
+ (i64.const 2912825531628789796)
+ (i64.const 0)
+ )
+ )
+)
diff --git a/test/passes/vacuum_ignore-implicit-traps.wast b/test/passes/vacuum_ignore-implicit-traps.wast
new file mode 100644
index 000000000..08b41a141
--- /dev/null
+++ b/test/passes/vacuum_ignore-implicit-traps.wast
@@ -0,0 +1,19 @@
+(module
+ (func $load-would-normally-have-side-effects (result i32)
+ (i64.ge_s
+ (block (result i64)
+ (drop
+ (i64.eq
+ (i64.load32_s
+ (i32.const 678585719)
+ )
+ (i64.const 8097879367757079605)
+ )
+ )
+ (i64.const 2912825531628789796)
+ )
+ (i64.const 0)
+ )
+ )
+)
+
diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm
index 6ac8c0ef1..a746c45e3 100644
--- a/test/wasm-only.fromasm
+++ b/test/wasm-only.fromasm
@@ -26,7 +26,116 @@
(export "illegalResult" (func $legalstub$result))
(export "keepAlive" (func $keepAlive))
(func $loads
- (nop)
+ (drop
+ (i32.load8_s
+ (i32.const 100)
+ )
+ )
+ (drop
+ (i32.load8_s
+ (i32.const 101)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 102)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 103)
+ )
+ )
+ (drop
+ (i32.load16_s align=1
+ (i32.const 104)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 105)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 106)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 107)
+ )
+ )
+ (drop
+ (i32.load align=1
+ (i32.const 108)
+ )
+ )
+ (drop
+ (i32.load align=2
+ (i32.const 109)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 110)
+ )
+ )
+ (drop
+ (f32.load
+ (i32.const 111)
+ )
+ )
+ (drop
+ (f32.load
+ (i32.const 112)
+ )
+ )
+ (drop
+ (f32.load align=1
+ (i32.const 113)
+ )
+ )
+ (drop
+ (f32.load align=2
+ (i32.const 114)
+ )
+ )
+ (drop
+ (f32.load
+ (i32.const 115)
+ )
+ )
+ (drop
+ (f64.load
+ (i32.const 116)
+ )
+ )
+ (drop
+ (f64.load
+ (i32.const 117)
+ )
+ )
+ (drop
+ (f64.load align=1
+ (i32.const 118)
+ )
+ )
+ (drop
+ (f64.load align=2
+ (i32.const 119)
+ )
+ )
+ (drop
+ (f64.load align=4
+ (i32.const 120)
+ )
+ )
+ (drop
+ (f64.load
+ (i32.const 121)
+ )
+ )
)
(func $stores
(local $0 i32)
@@ -249,6 +358,26 @@
(get_local $1)
)
)
+ (drop
+ (i64.load
+ (i32.const 120)
+ )
+ )
+ (drop
+ (i64.load
+ (i32.const 120)
+ )
+ )
+ (drop
+ (i64.load align=2
+ (i32.const 120)
+ )
+ )
+ (drop
+ (i64.load align=4
+ (i32.const 120)
+ )
+ )
(i64.store
(i32.const 120)
(tee_local $0
diff --git a/test/wasm-only.fromasm.clamp b/test/wasm-only.fromasm.clamp
index 6ac8c0ef1..a746c45e3 100644
--- a/test/wasm-only.fromasm.clamp
+++ b/test/wasm-only.fromasm.clamp
@@ -26,7 +26,116 @@
(export "illegalResult" (func $legalstub$result))
(export "keepAlive" (func $keepAlive))
(func $loads
- (nop)
+ (drop
+ (i32.load8_s
+ (i32.const 100)
+ )
+ )
+ (drop
+ (i32.load8_s
+ (i32.const 101)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 102)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 103)
+ )
+ )
+ (drop
+ (i32.load16_s align=1
+ (i32.const 104)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 105)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 106)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 107)
+ )
+ )
+ (drop
+ (i32.load align=1
+ (i32.const 108)
+ )
+ )
+ (drop
+ (i32.load align=2
+ (i32.const 109)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 110)
+ )
+ )
+ (drop
+ (f32.load
+ (i32.const 111)
+ )
+ )
+ (drop
+ (f32.load
+ (i32.const 112)
+ )
+ )
+ (drop
+ (f32.load align=1
+ (i32.const 113)
+ )
+ )
+ (drop
+ (f32.load align=2
+ (i32.const 114)
+ )
+ )
+ (drop
+ (f32.load
+ (i32.const 115)
+ )
+ )
+ (drop
+ (f64.load
+ (i32.const 116)
+ )
+ )
+ (drop
+ (f64.load
+ (i32.const 117)
+ )
+ )
+ (drop
+ (f64.load align=1
+ (i32.const 118)
+ )
+ )
+ (drop
+ (f64.load align=2
+ (i32.const 119)
+ )
+ )
+ (drop
+ (f64.load align=4
+ (i32.const 120)
+ )
+ )
+ (drop
+ (f64.load
+ (i32.const 121)
+ )
+ )
)
(func $stores
(local $0 i32)
@@ -249,6 +358,26 @@
(get_local $1)
)
)
+ (drop
+ (i64.load
+ (i32.const 120)
+ )
+ )
+ (drop
+ (i64.load
+ (i32.const 120)
+ )
+ )
+ (drop
+ (i64.load align=2
+ (i32.const 120)
+ )
+ )
+ (drop
+ (i64.load align=4
+ (i32.const 120)
+ )
+ )
(i64.store
(i32.const 120)
(tee_local $0