summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-12-20 19:38:07 -0800
committerGitHub <noreply@github.com>2019-12-20 19:38:07 -0800
commit8f78bb90561fa17791ae6b865c4238b5fca1b8d4 (patch)
tree9c87763572fcea5c399138da0c42067a531285e7
parent3f6fd583ca283c12f05c1258962cebdd2202e949 (diff)
downloadbinaryen-8f78bb90561fa17791ae6b865c4238b5fca1b8d4.tar.gz
binaryen-8f78bb90561fa17791ae6b865c4238b5fca1b8d4.tar.bz2
binaryen-8f78bb90561fa17791ae6b865c4238b5fca1b8d4.zip
Fix memory size calculation in MemoryPacking (#2548)
Because `memory.size` returns the size in number of pages, we have to multiply the size with the page size when converting `memory.init`.
-rw-r--r--src/passes/MemoryPacking.cpp7
-rw-r--r--test/passes/memory-packing_all-features.txt5
2 files changed, 10 insertions, 2 deletions
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index 18207026a..98c7cce00 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -140,7 +140,12 @@ struct MemoryPacking : public Pass {
builder.makeBinary(
OrInt32,
builder.makeBinary(
- GtUInt32, curr->dest, builder.makeHost(MemorySize, Name(), {})),
+ GtUInt32,
+ curr->dest,
+ builder.makeBinary(
+ MulInt32,
+ builder.makeConst(Literal(Memory::kPageSize)),
+ builder.makeHost(MemorySize, Name(), {}))),
builder.makeBinary(OrInt32, curr->offset, curr->size)),
builder.makeUnreachable()));
changed = true;
diff --git a/test/passes/memory-packing_all-features.txt b/test/passes/memory-packing_all-features.txt
index 5f6c5dacc..9b2eaad29 100644
--- a/test/passes/memory-packing_all-features.txt
+++ b/test/passes/memory-packing_all-features.txt
@@ -26,7 +26,10 @@
(i32.or
(i32.gt_u
(i32.const 0)
- (memory.size)
+ (i32.mul
+ (i32.const 65536)
+ (memory.size)
+ )
)
(i32.or
(i32.const 0)