-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement stuff required to elide instruction loading in yklua. #1642
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,7 @@ impl From<&VarLocation> for yksmp::Location { | |
todo!(">32 bit constant") | ||
} | ||
} | ||
VarLocation::ConstPtr(v) => yksmp::Location::LargeConstant(u64::try_from(*v).unwrap()), | ||
e => todo!("{:?}", e), | ||
} | ||
} | ||
|
@@ -1271,7 +1272,7 @@ impl<'a> Assemble<'a> { | |
.force_assign_inst_indirect(iidx, i32::try_from(frame_off).unwrap()); | ||
} | ||
VarLocation::ConstInt { bits, v } => { | ||
self.ra.assign_const(iidx, bits, v); | ||
self.ra.assign_const_int(iidx, bits, v); | ||
} | ||
e => panic!("{:?}", e), | ||
} | ||
|
@@ -2465,7 +2466,7 @@ impl<'a> Assemble<'a> { | |
// match. But since the value can't change we can safely ignore this. | ||
} | ||
VarLocation::Register(_reg) => (), // Handled in the earlier loop | ||
_ => todo!(), | ||
_ => todo!("{dst:?}"), | ||
} | ||
} | ||
|
||
|
@@ -2609,7 +2610,11 @@ impl<'a> Assemble<'a> { | |
); | ||
} | ||
VarLocation::ConstInt { bits, v } => { | ||
self.ra.assign_const(iidx, bits, v); | ||
self.ra.assign_const_int(iidx, bits, v); | ||
} | ||
VarLocation::ConstPtr(v) => { | ||
// unwrap can't fail because pointers are sized. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no |
||
self.ra.assign_const_ptr(iidx, v); | ||
} | ||
e => panic!("{:?}", e), | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -782,7 +782,20 @@ impl Opt { | |
loop { | ||
off += pa_inst.off(); | ||
match self.an.op_map(&self.m, pa_inst.ptr(&self.m)) { | ||
Operand::Const(_) => todo!(), | ||
Operand::Const(cidx) => { | ||
let Const::Ptr(cptr) = self.m.const_(cidx) else { | ||
panic!(); | ||
}; | ||
// Important details: | ||
// - offsets can be negative | ||
// - LLVM semantics require the offset to be sign extended or truncated to | ||
// the "pointer index type" before computing the offset. | ||
let cidx = self | ||
.m | ||
.insert_const(Const::Ptr((*cptr as isize + off as isize) as usize))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By This section of the llvm manual:
I must admit, I find this part of the documentation confusing. I hope I've interpreted it correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can split this into two cases: truncate and sign-extend.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, in terms of the |
||
self.m.replace(iidx, Inst::Const(cidx)); | ||
break; | ||
} | ||
Operand::Var(op_iidx) => { | ||
if let Inst::PtrAdd(x) = self.m.inst(op_iidx) { | ||
pa_inst = x; | ||
|
@@ -861,6 +874,7 @@ impl Opt { | |
debug_assert_eq!(lhs.bitw(), rhs.bitw()); | ||
lhs == rhs | ||
} | ||
(Const::Ptr(lhs), Const::Ptr(rhs)) => lhs == rhs, | ||
x => todo!("{x:?}"), | ||
}, | ||
}, | ||
|
@@ -1762,6 +1776,12 @@ mod test { | |
|
||
#[test] | ||
fn opt_ptradd() { | ||
// FIXME: The offset operand of ptr_add should allow specifying a type (e.g. `ptr_add %0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to be fixed in this PR. We need to make the optimiser tests as complete as possible, because reasoning about it is already beyond my pea brain. |
||
// 8i8`) so that we can test the different offset types that can arise. Requires some | ||
// parser hacking. | ||
// | ||
// FIXME: test two's compliment overflow/underflow of a ptr_add, which according to LLVM | ||
// semantics is permitted. Probably should come after fixing the above FIXME. | ||
Module::assert_ir_transform_eq( | ||
" | ||
entry: | ||
|
@@ -1795,6 +1815,24 @@ mod test { | |
black_box %0 | ||
", | ||
); | ||
|
||
// constant pointer optimisations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to test all the edge cases too e.g. adding to the max value etc. |
||
Module::assert_ir_transform_eq( | ||
" | ||
entry: | ||
%0: ptr = ptr_add 0x0, 0 | ||
%1: ptr = ptr_add 0x6, 10 | ||
black_box %0 | ||
black_box %1 | ||
", | ||
|m| opt(m).unwrap(), | ||
" | ||
... | ||
entry: | ||
black_box 0x0 | ||
black_box 0x10 | ||
", | ||
); | ||
} | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an
assert
masquerading as atodo
I think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just the result of copying code from elsewhere :) Will fix.