Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ struct OptimizeInstructions

// 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>();
Expand Down Expand Up @@ -975,6 +976,9 @@ struct OptimizeInstructions
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;
Expand Down
10 changes: 3 additions & 7 deletions test/emcc_hello_world.fromasm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions test/emcc_hello_world.fromasm.clamp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions test/emcc_hello_world.fromasm.imprecise
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/passes/optimize-instructions_enable-threads.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions test/passes/optimize-instructions_enable-threads.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down