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
10 changes: 10 additions & 0 deletions src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,17 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
}
}
}
} else if (auto* block = boolean->dynCast<Block>()) {
if (block->type == i32 && block->list.size() > 0) {
block->list.back() = optimizeBoolean(block->list.back());
}
} else if (auto* iff = boolean->dynCast<If>()) {
if (iff->type == i32) {
iff->ifTrue = optimizeBoolean(iff->ifTrue);
iff->ifFalse = optimizeBoolean(iff->ifFalse);
}
}
// TODO: recurse into br values?
return boolean;
}

Expand Down
9 changes: 3 additions & 6 deletions test/emcc_O2_hello_world.fromasm
Original file line number Diff line number Diff line change
Expand Up @@ -9600,12 +9600,9 @@
(i32.const 12)
)
)
(i32.ne
(call $___syscall54
(i32.const 54)
(get_local $3)
)
(i32.const 0)
(call $___syscall54
(i32.const 54)
(get_local $3)
)
)
)
Expand Down
9 changes: 3 additions & 6 deletions test/emcc_O2_hello_world.fromasm.imprecise
Original file line number Diff line number Diff line change
Expand Up @@ -9598,12 +9598,9 @@
(i32.const 12)
)
)
(i32.ne
(call $___syscall54
(i32.const 54)
(get_local $3)
)
(i32.const 0)
(call $___syscall54
(i32.const 54)
(get_local $3)
)
)
)
Expand Down
17 changes: 17 additions & 0 deletions test/passes/optimize-instructions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,21 @@
)
(i32.const 1)
)
(func $recurse-bool (type $1)
(if
(if i32
(i32.const 1)
(call $ne0)
(call $ne0)
)
(nop)
)
(if
(block $block i32
(nop)
(call $ne0)
)
(nop)
)
)
)
17 changes: 17 additions & 0 deletions test/passes/optimize-instructions.wast
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,21 @@
)
(i32.const 1)
)
(func $recurse-bool
(if
(if i32
(i32.const 1)
(i32.ne (call $ne0) (i32.const 0))
(i32.ne (call $ne0) (i32.const 0))
)
(nop)
)
(if
(block i32
(nop)
(i32.ne (call $ne0) (i32.const 0))
)
(nop)
)
)
)