souper-harvest: ensure that select conditions are of type i1
This commit is contained in:
@@ -29,7 +29,7 @@ peepmatic = { path = "../peepmatic", optional = true, version = "0.68.0" }
|
||||
peepmatic-traits = { path = "../peepmatic/crates/traits", optional = true, version = "0.68.0" }
|
||||
peepmatic-runtime = { path = "../peepmatic/crates/runtime", optional = true, version = "0.68.0" }
|
||||
regalloc = { version = "0.0.31" }
|
||||
souper-ir = { version = "2.0.0", optional = true }
|
||||
souper-ir = { version = "2.1.0", optional = true }
|
||||
wast = { version = "28.0.0", optional = true }
|
||||
# It is a goal of the cranelift-codegen crate to have minimal external dependencies.
|
||||
# Please don't add any unless they are essential to the task of creating binary
|
||||
|
||||
@@ -392,6 +392,28 @@ fn harvest_candidate_lhs(
|
||||
}
|
||||
(ir::Opcode::Select, _) => {
|
||||
let a = arg(allocs, 0);
|
||||
|
||||
// While Cranelift allows any width condition for
|
||||
// `select`, Souper requires an `i1`.
|
||||
let a = match a {
|
||||
ast::Operand::Value(id) => match lhs.get_value(id).r#type {
|
||||
Some(ast::Type { width: 1 }) => a,
|
||||
_ => lhs
|
||||
.assignment(
|
||||
None,
|
||||
Some(ast::Type { width: 1 }),
|
||||
ast::Instruction::Trunc { a },
|
||||
vec![],
|
||||
)
|
||||
.into(),
|
||||
},
|
||||
ast::Operand::Constant(ast::Constant { value, .. }) => ast::Constant {
|
||||
value: (value != 0) as _,
|
||||
r#type: Some(ast::Type { width: 1 }),
|
||||
}
|
||||
.into(),
|
||||
};
|
||||
|
||||
let b = arg(allocs, 1);
|
||||
let c = arg(allocs, 2);
|
||||
ast::Instruction::Select { a, b, c }.into()
|
||||
|
||||
Reference in New Issue
Block a user