Skip to content

Commit

Permalink
Optimise PtrAdds that were optimised from DynPtrAdd.
Browse files Browse the repository at this point in the history
In essence, when we've been able to convert a `DynPtrAdd` to a `PtrAdd`,
we can then run our existing `PtrAdd` optimisation on the result. This
can then show up further optimisation opportunities to CSE.
  • Loading branch information
ltratt committed Feb 27, 2025
1 parent 88fc171 commit 30d957c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ykrt/src/compile/jitc_yk/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,9 @@ impl Opt {
Operand::Const(cidx) => self.m.replace(iidx, Inst::Const(cidx)),
}
} else {
self.m
.replace(iidx, Inst::PtrAdd(PtrAddInst::new(inst.ptr(&self.m), off)));
let pa_inst = PtrAddInst::new(inst.ptr(&self.m), off);
self.m.replace(iidx, Inst::PtrAdd(pa_inst.clone()));
self.opt_ptradd(iidx, pa_inst)?;
}
}

Expand Down Expand Up @@ -1776,7 +1777,7 @@ mod test {
}

#[test]
fn opt_dynptradd_const() {
fn opt_dynptradd() {
Module::assert_ir_transform_eq(
"
entry:
Expand Down Expand Up @@ -1807,6 +1808,23 @@ mod test {
black_box 0x1234
",
);

Module::assert_ir_transform_eq(
"
entry:
%0: ptr = param reg
%1: ptr = ptr_add %0, -4
%2: ptr = dyn_ptr_add %1, 1i64, 4
black_box %2
",
|m| opt(m).unwrap(),
"
...
entry:
%0: ptr = param ...
black_box %0
",
);
}

#[test]
Expand Down

0 comments on commit 30d957c

Please sign in to comment.