summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/OptimizeInstructions.cpp4
-rw-r--r--test/emcc_hello_world.fromasm10
-rw-r--r--test/emcc_hello_world.fromasm.clamp10
-rw-r--r--test/emcc_hello_world.fromasm.imprecise10
-rw-r--r--test/passes/optimize-instructions_enable-threads.txt10
-rw-r--r--test/passes/optimize-instructions_enable-threads.wast10
6 files changed, 33 insertions, 21 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 3b053a5ca..4478a7bdd 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -939,6 +939,7 @@ private:
// Optimize given that the expression is flowing into a boolean context
Expression* optimizeBoolean(Expression* boolean) {
+ // TODO use a general getFallthroughs
if (auto* unary = boolean->dynCast<Unary>()) {
if (unary && unary->op == EqZInt32) {
auto* unary2 = unary->value->dynCast<Unary>();
@@ -975,6 +976,9 @@ private:
iff->ifTrue = optimizeBoolean(iff->ifTrue);
iff->ifFalse = optimizeBoolean(iff->ifFalse);
}
+ } else if (auto* select = boolean->dynCast<Select>()) {
+ select->ifTrue = optimizeBoolean(select->ifTrue);
+ select->ifFalse = optimizeBoolean(select->ifFalse);
}
// TODO: recurse into br values?
return boolean;
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 25cbe7176..002fdbd94 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -10329,13 +10329,9 @@
(block
(br_if $label$break$L279
(select
- (i32.eqz
- (i32.eqz
- (local.tee $3
- (i32.load
- (i32.const 616)
- )
- )
+ (local.tee $3
+ (i32.load
+ (i32.const 616)
)
)
(i32.const 0)
diff --git a/test/emcc_hello_world.fromasm.clamp b/test/emcc_hello_world.fromasm.clamp
index 8feba2827..3f39e80f0 100644
--- a/test/emcc_hello_world.fromasm.clamp
+++ b/test/emcc_hello_world.fromasm.clamp
@@ -10379,13 +10379,9 @@
(block
(br_if $label$break$L279
(select
- (i32.eqz
- (i32.eqz
- (local.tee $3
- (i32.load
- (i32.const 616)
- )
- )
+ (local.tee $3
+ (i32.load
+ (i32.const 616)
)
)
(i32.const 0)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 8bb8c257b..b3e2c99c7 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -10225,13 +10225,9 @@
(block
(br_if $label$break$L279
(select
- (i32.eqz
- (i32.eqz
- (local.tee $3
- (i32.load
- (i32.const 616)
- )
- )
+ (local.tee $3
+ (i32.load
+ (i32.const 616)
)
)
(i32.const 0)
diff --git a/test/passes/optimize-instructions_enable-threads.txt b/test/passes/optimize-instructions_enable-threads.txt
index 393d49112..f54b6ae99 100644
--- a/test/passes/optimize-instructions_enable-threads.txt
+++ b/test/passes/optimize-instructions_enable-threads.txt
@@ -3293,6 +3293,16 @@
)
)
)
+ (func $select-into-arms (; 77 ;) (type $FUNCSIG$vii) (param $x i32) (param $y i32)
+ (if
+ (select
+ (local.get $x)
+ (local.get $y)
+ (local.get $y)
+ )
+ (unreachable)
+ )
+ )
)
(module
(type $FUNCSIG$v (func))
diff --git a/test/passes/optimize-instructions_enable-threads.wast b/test/passes/optimize-instructions_enable-threads.wast
index fa683ca78..dfcaea597 100644
--- a/test/passes/optimize-instructions_enable-threads.wast
+++ b/test/passes/optimize-instructions_enable-threads.wast
@@ -3738,6 +3738,16 @@
))
;; TODO: more stuff here
)
+ (func $select-into-arms (param $x i32) (param $y i32)
+ (if
+ (select
+ (i32.eqz (i32.eqz (local.get $x)))
+ (i32.eqz (i32.eqz (local.get $y)))
+ (local.get $y)
+ )
+ (unreachable)
+ )
+ )
)
(module
(import "env" "memory" (memory $0 (shared 256 256)))