summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-02-12 16:37:45 -0800
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-02-16 22:45:38 -0800
commit6affe6fb4d06550a40b4d73efe19c085317854d7 (patch)
treec615bf8c36197fd7b3687a3b04ecd911b1325e77
parent85d2c4ffdaf3934f7e529cc43842a03c3304107b (diff)
downloadbinaryen-6affe6fb4d06550a40b4d73efe19c085317854d7.tar.gz
binaryen-6affe6fb4d06550a40b4d73efe19c085317854d7.tar.bz2
binaryen-6affe6fb4d06550a40b4d73efe19c085317854d7.zip
handle load in getMaxBits
-rw-r--r--src/passes/OptimizeInstructions.cpp2
-rw-r--r--test/passes/optimize-instructions.txt20
-rw-r--r--test/passes/optimize-instructions.wast38
3 files changed, 60 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index d28bf21a5..6dbb1b7e8 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -231,6 +231,8 @@ static Index getMaxBits(Expression* curr) {
} else if (auto* set = curr->dynCast<SetLocal>()) {
// a tee passes through the value
return getMaxBits(set->value);
+ } else if (auto* load = curr->dynCast<Load>()) {
+ return 8 * load->bytes;
}
switch (curr->type) {
case i32: return 32;
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index 9819cb8c7..01f1070f7 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -1218,4 +1218,24 @@
)
)
)
+ (func $sign-ext-load (type $4) (param $0 i32) (param $1 i32)
+ (drop
+ (i32.load8_s
+ (i32.const 256)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.load8_s
+ (i32.const 256)
+ )
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.load16_s
+ (i32.const 256)
+ )
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 1f0cd9094..9cdec0a6c 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -1525,4 +1525,42 @@
)
)
)
+ (func $sign-ext-load (param $0 i32) (param $1 i32)
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.load8_s ;; one byte, so perfect
+ (i32.const 256)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.load8_s ;; one byte, but reduced to 7
+ (i32.const 256)
+ )
+ (i32.const 1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.load16_s ;; two, so perfect
+ (i32.const 256)
+ )
+ (i32.const 16)
+ )
+ (i32.const 16)
+ )
+ )
+ )
)