summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h4
-rw-r--r--test/unit.asm.js5
-rw-r--r--test/unit.fromasm5
-rw-r--r--test/unit.fromasm.imprecise5
-rw-r--r--test/unit.fromasm.imprecise.no-opts7
-rw-r--r--test/unit.fromasm.no-opts7
6 files changed, 32 insertions, 1 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 0cb9b8dbe..059e51c59 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -1819,7 +1819,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
// if there is a shift, we can just look through it, etc.
processUnshifted = [&](Ref ptr, unsigned bytes) {
auto shifts = bytesToShift(bytes);
- if (ptr[0] == BINARY && ptr[1] == RSHIFT && ptr[3][0] == NUM && ptr[3][1]->getInteger() == shifts) {
+ // HEAP?[addr >> ?], or HEAP8[x | 0]
+ if ((ptr[0] == BINARY && ptr[1] == RSHIFT && ptr[3][0] == NUM && ptr[3][1]->getInteger() == shifts) ||
+ (bytes == 1 && ptr[0] == BINARY && ptr[1] == OR && ptr[3][0] == NUM && ptr[3][1]->getInteger() == 0)) {
return process(ptr[2]); // look through it
} else if (ptr[0] == NUM) {
// constant, apply a shift (e.g. HEAP32[1] is address 4)
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 8f0812e29..25aed0834 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -319,6 +319,11 @@ function asm(global, env, buffer) {
return 0;
}
+ function heap8NoShift(x) {
+ x = x | 0;
+ return HEAP8[x | 0] | 0;
+ }
+
function z() {
}
function w() {
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 0260adb81..98202a4ec 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -575,4 +575,9 @@
)
(i32.const 0)
)
+ (func $heap8NoShift (param $0 i32) (result i32)
+ (i32.load8_s
+ (get_local $0)
+ )
+ )
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 5ebe88c6f..493ebb67e 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -556,4 +556,9 @@
)
(i32.const 0)
)
+ (func $heap8NoShift (param $0 i32) (result i32)
+ (i32.load8_s
+ (get_local $0)
+ )
+ )
)
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index 7fdd01aaa..89a448a82 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -956,6 +956,13 @@
(i32.const 0)
)
)
+ (func $heap8NoShift (param $x i32) (result i32)
+ (return
+ (i32.load8_s
+ (get_local $x)
+ )
+ )
+ )
(func $z
(nop)
)
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index 14c4d6615..f1253c849 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -962,6 +962,13 @@
(i32.const 0)
)
)
+ (func $heap8NoShift (param $x i32) (result i32)
+ (return
+ (i32.load8_s
+ (get_local $x)
+ )
+ )
+ )
(func $z
(nop)
)