fixing a glaring bug, where the elidded offset is also offset

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-15 17:42:20 +01:00
parent 48a0c8d0b9
commit f9c47f86ad
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
4 changed files with 66 additions and 5 deletions

View file

@ -1673,6 +1673,26 @@ main := fn(): void {
### Just Testing Optimizations ### Just Testing Optimizations
#### elide_stack_offsets_for_parameters_correctly
```hb
A := struct {
f: uint,
s: B,
}
B := struct {
a: uint,
b: uint,
}
main := fn(): uint {
a := A.(1, .(0, 0))
return pass(a.s)
}
pass := fn(s: B): uint return s.a + s.b
```
#### null_check_test #### null_check_test
```hb ```hb
get_ptr := fn(): ?^uint return null get_ptr := fn(): ?^uint return null

View file

@ -4,7 +4,7 @@ use {
reg::{self, Reg}, reg::{self, Reg},
HbvmBackend, Nid, Nodes, PLoc, Reloc, TypedReloc, HbvmBackend, Nid, Nodes, PLoc, Reloc, TypedReloc,
}, },
lexer::TokenKind, lexer::{Token, TokenKind},
parser, quad_sort, parser, quad_sort,
son::{Kind, ARG_START, MEM, VOID}, son::{Kind, ARG_START, MEM, VOID},
ty::{self, Arg, Loc, Module, Offset, Sig, Types}, ty::{self, Arg, Loc, Module, Offset, Sig, Types},
@ -133,10 +133,22 @@ impl HbvmBackend {
res.node_to_reg[allc as usize] res.node_to_reg[allc as usize]
}; };
let offset_atr = |allc: Nid, offsets: &[Offset]| { let offset_atr = |pallc: Nid, offsets: &[Offset]| {
let allc = strip_load(allc); let allc = strip_load(pallc);
if nodes.is_locked(allc) && nodes[allc].kind == Kind::Stck { if nodes.is_locked(allc) {
return (reg::STACK_PTR, offsets[allc as usize] as u64); let (region, offset) = nodes.strip_offset(allc, ty::Id::VOID, tys);
match nodes[region].kind {
Kind::Stck => {
return (
reg::STACK_PTR,
offsets[region as usize] as u64 + offset as u64,
)
}
_ => {
assert_alloc_use(region);
return (res.node_to_reg[region as usize], offset as u64);
}
}
} }
assert_alloc_use(allc); assert_alloc_use(allc);

View file

@ -6037,6 +6037,7 @@ mod tests {
inline_return_stack; inline_return_stack;
// Just Testing Optimizations; // Just Testing Optimizations;
elide_stack_offsets_for_parameters_correctly;
const_folding_with_arg; const_folding_with_arg;
branch_assignments; branch_assignments;
exhaustive_loop_testing; exhaustive_loop_testing;

View file

@ -0,0 +1,28 @@
main:
ADDI64 r254, r254, -40d
ST r31, r254, 24a, 16h
LI64 r32, 1d
ST r32, r254, 0a, 8h
ST r0, r254, 8a, 8h
ST r0, r254, 16a, 8h
LD r2, r254, 8a, 16h
JAL r31, r0, :pass
CP r32, r1
CP r1, r32
LD r31, r254, 24a, 16h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
pass:
ADDI64 r254, r254, -16d
ST r2, r254, 0a, 16h
ADDI64 r2, r254, 0d
CP r13, r2
LD r14, r13, 0a, 8h
LD r13, r13, 8a, 8h
ADD64 r13, r13, r14
CP r1, r13
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
code size: 235
ret: 0
status: Ok(())