Cranelift: Fix select condition harvesting (#5662)

Souper requires an `i1` condition value, we don't and will implicitly check
against 0. We were truncating conditions but should actually be doing the
comparison against `0`.
This commit is contained in:
Nick Fitzgerald
2023-01-30 21:25:14 -08:00
committed by GitHub
parent cc768f22a2
commit bf4d0e9212

View File

@@ -387,7 +387,8 @@ fn harvest_candidate_lhs(
let a = arg(allocs, 0); let a = arg(allocs, 0);
// While Cranelift allows any width condition for // While Cranelift allows any width condition for
// `select`, Souper requires an `i1`. // `select` and checks it against `0`, Souper requires
// an `i1`. So insert a `ne %x, 0` as needed.
let a = match a { let a = match a {
ast::Operand::Value(id) => match lhs.get_value(id).r#type { ast::Operand::Value(id) => match lhs.get_value(id).r#type {
Some(ast::Type { width: 1 }) => a, Some(ast::Type { width: 1 }) => a,
@@ -395,7 +396,14 @@ fn harvest_candidate_lhs(
.assignment( .assignment(
None, None,
Some(ast::Type { width: 1 }), Some(ast::Type { width: 1 }),
ast::Instruction::Trunc { a }, ast::Instruction::Ne {
a,
b: ast::Constant {
value: 0,
r#type: None,
}
.into(),
},
vec![], vec![],
) )
.into(), .into(),