A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Cranelift: remove the `sdiv_imm` instruction (#13548)
Nick Fitzgerald63a79ca3f27e
diff --git a/cranelift/codegen/meta/src/shared/instructions.rs b/cranelift/codegen/meta/src/shared/instructions.rsindex cd74860dbc..a0203f95e6 100644--- a/cranelift/codegen/meta/src/shared/instructions.rs+++ b/cranelift/codegen/meta/src/shared/instructions.rs@@ -1947,7 +1947,8 @@ pub(crate) fn define(.operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)]).operands_out(vec![Operand::new("a", iB)]).can_trap()- .side_effects_idempotent(),+ .side_effects_idempotent()+ .inst_builder_imm_method(true),);ig.push(@@ -1982,24 +1983,6 @@ pub(crate) fn define(.side_effects_idempotent(),);- ig.push(- Inst::new(- "sdiv_imm",- r#"- Signed integer division by an immediate constant.-- Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.-- This operation traps if the divisor is zero, or if the result is not- representable in `B` bits two's complement. This only happens- when `x = -2^{B-1}, Y = -1`.- "#,- &formats.binary_imm64,- )- .operands_in(vec![Operand::new("x", iB), Operand::new("Y", &imm.imm64)])- .operands_out(vec![Operand::new("a", iB)]),- );-ig.push(Inst::new("urem_imm",diff --git a/cranelift/codegen/src/ir/instructions.rs b/cranelift/codegen/src/ir/instructions.rsindex e5c05efedb..fd2c6d7809 100644--- a/cranelift/codegen/src/ir/instructions.rs+++ b/cranelift/codegen/src/ir/instructions.rs@@ -647,7 +647,7 @@ impl InstructionData {arg: _,imm,} => {- if *opcode == Opcode::SdivImm || *opcode == Opcode::SremImm {+ if *opcode == Opcode::SremImm {*imm = imm.mask_to_width(bit_width);}}diff --git a/cranelift/codegen/src/legalizer/mod.rs b/cranelift/codegen/src/legalizer/mod.rsindex 1fab7f42fd..35be9a826e 100644--- a/cranelift/codegen/src/legalizer/mod.rs+++ b/cranelift/codegen/src/legalizer/mod.rs@@ -204,7 +204,7 @@ fn expand_binary_imm64(pos.goto_inst(inst);let is_signed = match opcode {- ir::Opcode::IrsubImm | ir::Opcode::SdivImm | ir::Opcode::SremImm => true,+ ir::Opcode::IrsubImm | ir::Opcode::SremImm => true,_ => false,};@@ -243,9 +243,6 @@ fn expand_binary_imm64(// note: arg order reversedreplace.isub(imm, arg);}- ir::Opcode::SdivImm => {- replace.sdiv(arg, imm);- }ir::Opcode::SremImm => {replace.srem(arg, imm);}diff --git a/cranelift/codegen/src/souper_harvest.rs b/cranelift/codegen/src/souper_harvest.rsindex 416e9703dc..982e536171 100644--- a/cranelift/codegen/src/souper_harvest.rs+++ b/cranelift/codegen/src/souper_harvest.rs@@ -99,7 +99,6 @@ fn harvest_candidate_lhs(| ir::Opcode::Imul| ir::Opcode::Udiv| ir::Opcode::Sdiv- | ir::Opcode::SdivImm| ir::Opcode::Urem| ir::Opcode::UremImm| ir::Opcode::Srem@@ -208,17 +207,6 @@ fn harvest_candidate_lhs(let b = arg(allocs, 1);ast::Instruction::Sdiv { a, b }.into()}- (ir::Opcode::SdivImm, ir::InstructionData::BinaryImm64 { imm, .. }) => {- let a = arg(allocs, 0);- let value: i64 = (*imm).into();- let value: i128 = value.into();- let b = ast::Constant {- value,- r#type: souper_type_of(&func.dfg, val),- }- .into();- ast::Instruction::Sdiv { a, b }.into()- }(ir::Opcode::Urem, _) => {let a = arg(allocs, 0);let b = arg(allocs, 1);diff --git a/cranelift/fuzzgen/src/function_generator.rs b/cranelift/fuzzgen/src/function_generator.rsindex ca1deec462..cfea410027 100644--- a/cranelift/fuzzgen/src/function_generator.rs+++ b/cranelift/fuzzgen/src/function_generator.rs@@ -925,7 +925,6 @@ static OPCODE_SIGNATURES: LazyLock<Vec<OpcodeSignature>> = LazyLock::new(|| {(Opcode::GetReturnAddress),(Opcode::Blendv),(Opcode::X86Pmulhrsw),- (Opcode::SdivImm),(Opcode::UremImm),(Opcode::SremImm),(Opcode::IrsubImm),diff --git a/cranelift/interpreter/src/interpreter.rs b/cranelift/interpreter/src/interpreter.rsindex 0be8fc473b..ae9bc432a3 100644--- a/cranelift/interpreter/src/interpreter.rs+++ b/cranelift/interpreter/src/interpreter.rs@@ -620,7 +620,8 @@ mod tests {let code = "function %test() -> i8 {block0:v0 = iconst.i32 -2147483648- v1 = sdiv_imm.i32 v0, -1+ v2 = iconst.i32 -1+ v1 = sdiv v0, v2return v1}";diff --git a/cranelift/interpreter/src/step.rs b/cranelift/interpreter/src/step.rsindex 1f32441719..660a505363 100644--- a/cranelift/interpreter/src/step.rs+++ b/cranelift/interpreter/src/step.rs@@ -718,7 +718,6 @@ whereOpcode::Sdiv => binary_can_trap(DataValueExt::sdiv, arg(0), arg(1))?,Opcode::Urem => binary_can_trap(DataValueExt::urem, arg(0), arg(1))?,Opcode::Srem => binary_can_trap(DataValueExt::srem, arg(0), arg(1))?,- Opcode::SdivImm => binary_can_trap(DataValueExt::sdiv, arg(0), imm_as_ctrl_ty()?)?,Opcode::UremImm => binary_can_trap(DataValueExt::urem, arg(0), imm_as_ctrl_ty()?)?,Opcode::SremImm => binary_can_trap(DataValueExt::srem, arg(0), imm_as_ctrl_ty()?)?,Opcode::IrsubImm => binary(DataValueExt::sub, imm_as_ctrl_ty()?, arg(0))?,