diff --git a/Cargo.lock b/Cargo.lock index f177b974ab..716f156bfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index 3f6874778e..cc0a6fd62d 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -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 diff --git a/cranelift/codegen/src/souper_harvest.rs b/cranelift/codegen/src/souper_harvest.rs index 7f8c34d4a2..4884ae5002 100644 --- a/cranelift/codegen/src/souper_harvest.rs +++ b/cranelift/codegen/src/souper_harvest.rs @@ -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() diff --git a/cranelift/peepmatic/crates/souper/Cargo.toml b/cranelift/peepmatic/crates/souper/Cargo.toml index e5717ecea8..84bf6f52e0 100644 --- a/cranelift/peepmatic/crates/souper/Cargo.toml +++ b/cranelift/peepmatic/crates/souper/Cargo.toml @@ -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]