summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-02-11 22:04:22 -0800
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-02-16 22:45:37 -0800
commit85d2c4ffdaf3934f7e529cc43842a03c3304107b (patch)
treef9a834a811b0af10270a08a1d339c1852d6f816b
parentc06b3762a09e95443fd0f159b2675209db1dbb29 (diff)
downloadbinaryen-85d2c4ffdaf3934f7e529cc43842a03c3304107b.tar.gz
binaryen-85d2c4ffdaf3934f7e529cc43842a03c3304107b.tar.bz2
binaryen-85d2c4ffdaf3934f7e529cc43842a03c3304107b.zip
handle tee_local in getMaxBits
-rw-r--r--src/passes/OptimizeInstructions.cpp3
-rw-r--r--test/passes/optimize-instructions.txt18
-rw-r--r--test/passes/optimize-instructions.wast24
3 files changed, 45 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index cf5ad982e..d28bf21a5 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -228,6 +228,9 @@ static Index getMaxBits(Expression* curr) {
case WrapInt64: return std::min(Index(32), getMaxBits(unary->value));
default: {}
}
+ } else if (auto* set = curr->dynCast<SetLocal>()) {
+ // a tee passes through the value
+ return getMaxBits(set->value);
}
switch (curr->type) {
case i32: return 32;
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index d36f1ffad..9819cb8c7 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -1200,4 +1200,22 @@
)
)
)
+ (func $sign-ext-tee (type $4) (param $0 i32) (param $1 i32)
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (tee_local $0
+ (i32.const 128)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (tee_local $0
+ (i32.const 127)
+ )
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 6cba3d51f..1f0cd9094 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -1501,4 +1501,28 @@
)
)
)
+ (func $sign-ext-tee (param $0 i32) (param $1 i32)
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (tee_local $0
+ (i32.const 128) ;; too big
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (tee_local $0
+ (i32.const 127) ;; just right
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
)