souper-harvest: ensure that select conditions are of type i1

This commit is contained in:
Nick Fitzgerald
2020-10-16 11:18:43 -07:00
parent f7cf771ee6
commit 1efdf10ca7
4 changed files with 26 additions and 4 deletions

View File

@@ -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()