afonso360 opened PR #4602 from iadd_imm_fix_sext
to main
:
:wave: Hey,
This PR alters the behaviour of
*_imm
instructions to sign extend their immediate argument when the control type isi128
.This comes from a fuzzer issue where the interpreter was sign extending the immediates but the legalizations were not.
Fixes: #4568
afonso360 updated PR #4602 from iadd_imm_fix_sext
to main
.
afonso360 updated PR #4602 from iadd_imm_fix_sext
to main
.
afonso360 edited PR #4602 from iadd_imm_fix_sext
to main
:
:wave: Hey,
This PR alters the behaviour of
*_imm
instructions to sign extend their immediate argument when the control type isi128
.This comes from a fuzzer issue where the interpreter was sign extending the immediates but the legalizations were not.
Fixes: #4568
Fixes: #4641
afonso360 updated PR #4602 from iadd_imm_fix_sext
to main
.
afonso360 has marked PR #4602 as ready for review.
jameysharp submitted PR review.
jameysharp created PR review comment:
It looks like it's a behavioral change if we panic here. The outer match just skips the instruction if it doesn't have an expansion for it. Maybe that's why the previous implementation duplicated so much code? I think @cfallin probably needs to weigh in on how this case should be handled.
Gotta say, though, I _really_ like how much shorter your version is. I hope we can preserve that clarity even if this bit has to change.
It might help to introduce a function that's something like this (but I haven't tested this code, let alone compiled it):
fn imm_const(pos: &mut FuncCursor, arg: Value, imm: Imm64) -> Value { let ty = pos.func.dfg.value_type(arg); let imm = pos.ins().iconst(ty, imm); if ty == I128 { let imm = pos.ins().iconst(I64, imm); pos.ins().sextend(I128, imm) } else { pos.ins().iconst(ty.lane_type(), imm) } }
jameysharp submitted PR review.
cfallin submitted PR review.
cfallin created PR review comment:
Yes, we don't want to hit an
unimplemented!()
here; I think we just want an empty match-arm body (_ => {}
) instead. That way we still construct theimm
but we just don't do anything with it.
cfallin submitted PR review.
jameysharp created PR review comment:
Wouldn't an empty match-arm body there cause
simple_legalize
to loop, trying to legalize the same instruction repeatedly?
jameysharp submitted PR review.
cfallin created PR review comment:
The toplevel loop is a
while let Some(inst) = pos.next_inst()
, so it's stepping through insts with no action taken in the loop body. Though actually the more precise thing to do is to replicate the fallback_ => { ... }
below, which setsprev_pos
first then continues, I think.
cfallin submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
The statement after the
match
ispos.set_position(prev_pos);
and the intent appears to be to re-examine the result of every legalization. So it looks to me like termination of this function relies on every match arm replacing the instruction that it originally matched on. But yes, copying theprev_pos
assignment from the fallback case should work, I think.
akirilov-arm submitted PR review.
akirilov-arm submitted PR review.
akirilov-arm created PR review comment:
I don't have an opinion myself yet, but is sign-extending the best approach in this case?
akirilov-arm created PR review comment:
Ditto for all logical operations and rotations.
akirilov-arm created PR review comment:
Ditto.
afonso360 updated PR #4602 from iadd_imm_fix_sext
to main
.
afonso360 requested cfallin for a review on PR #4602.
cfallin submitted PR review.
cfallin has enabled auto merge for PR #4602.
cfallin merged PR #4602.
Last updated: Nov 22 2024 at 16:03 UTC