Skip to content

Commit

Permalink
Update i64_from_iconst to only match iconst (#8739)
Browse files Browse the repository at this point in the history
Previously this extractor would additionally match `f32const` and
`f64const` which while theoretically not the end of the world can be
confusing. Nowadays switch it to instead only matching the `iconst`
instruction, as the name implies, and if necessary matching float
constants is probably best done through separate ISLE lowering rules.

Closes #8723
  • Loading branch information
alexcrichton authored Jun 4, 2024
1 parent b010bfd commit 9f69578
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ macro_rules! isle_lower_prelude_methods {
#[inline]
fn i64_from_iconst(&mut self, val: Value) -> Option<i64> {
let inst = self.def_inst(val)?;
let constant = self.lower_ctx.get_constant(inst)? as i64;
let constant = match self.lower_ctx.data(inst) {
InstructionData::UnaryImm {
opcode: Opcode::Iconst,
imm,
} => imm.bits(),
_ => return None,
};
let ty = self.lower_ctx.output_ty(inst, 0);
let shift_amt = std::cmp::max(0, 64 - self.ty_bits(ty));
Some((constant << shift_amt) >> shift_amt)
Expand Down

0 comments on commit 9f69578

Please sign in to comment.