mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Cheap optimisation for boolean conditions in Switch statements
This commit is contained in:
parent
78a7e45b8f
commit
3a751aa3e8
1 changed files with 24 additions and 16 deletions
|
@ -4,7 +4,7 @@ use code_builder::Align;
|
|||
use roc_collections::all::MutMap;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::ir::{CallType, Expr, JoinPointId, Literal, Proc, Stmt};
|
||||
use roc_mono::layout::{Layout, LayoutIds};
|
||||
use roc_mono::layout::{Builtin, Layout, LayoutIds};
|
||||
|
||||
use crate::layout::WasmLayout;
|
||||
use crate::low_level::{build_call_low_level, LowlevelBuildResult};
|
||||
|
@ -326,6 +326,7 @@ impl<'a> WasmBackend<'a> {
|
|||
self.start_block(BlockType::NoResult)
|
||||
}
|
||||
|
||||
let is_bool = matches!(cond_layout, Layout::Builtin(Builtin::Int1));
|
||||
let cond_type = WasmLayout::new(cond_layout).value_type();
|
||||
|
||||
// then, we jump whenever the value under scrutiny is equal to the value of a branch
|
||||
|
@ -334,6 +335,12 @@ impl<'a> WasmBackend<'a> {
|
|||
self.storage
|
||||
.load_symbols(&mut self.code_builder, &[*cond_symbol]);
|
||||
|
||||
if is_bool {
|
||||
// We already have a bool, don't need to compare against a const to get one
|
||||
if *value == 0 {
|
||||
self.code_builder.i32_eqz();
|
||||
}
|
||||
} else {
|
||||
match cond_type {
|
||||
ValueType::I32 => {
|
||||
self.code_builder.i32_const(*value as i32);
|
||||
|
@ -352,6 +359,7 @@ impl<'a> WasmBackend<'a> {
|
|||
self.code_builder.f64_eq();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "break" out of `i` surrounding blocks
|
||||
self.code_builder.br_if(i as u32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue