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

4
Cargo.lock generated
View File

@@ -1989,9 +1989,9 @@ checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
[[package]]
name = "souper-ir"
version = "2.0.0"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c7eaed476845a4755001a900e0412dabd356d312ddc35dd32ff91de266b1558"
checksum = "a50c18ce33988e1973003afbaa66e6a465ad7a614dc33f246879ccc209c2c044"
dependencies = [
"id-arena",
]

View File

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

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

View File

@@ -10,7 +10,7 @@ description = "Converting Souper optimizations into Peepmatic DSL"
[dependencies]
anyhow = "1"
souper-ir = { version = "2.0.0", features = ["parse"] }
souper-ir = { version = "2.1.0", features = ["parse"] }
log = "0.4.8"
[dev-dependencies]