fixing storing struct pointer bug

This commit is contained in:
Jakub Doka 2024-10-28 18:39:42 +01:00
parent 33d78fbc52
commit b4b3bae104
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
4 changed files with 26 additions and 10 deletions

View file

@ -1144,3 +1144,15 @@ main := fn(): uint {
return f
}
```
#### aliasing_overoptimization
```hb
Foo := struct {ptr: ^uint, rnd: uint}
main := fn(): uint {
mem := &2
stru := Foo.(mem, 0);
*stru.ptr = 0
return *mem
}
```

View file

@ -3885,5 +3885,6 @@ mod tests {
loop_stores;
dead_code_in_loop;
infinite_loop_after_peephole;
aliasing_overoptimization;
}
}

View file

@ -675,7 +675,7 @@ impl<'a> Function<'a> {
"{:?}",
self.nodes[nid]
);
debug_assert_eq!(self.nodes[nid].lock_rc, 0, "{:?}", self.nodes[nid]);
debug_assert_eq!(self.nodes[nid].lock_rc, 0, "{nid} {:?}", self.nodes[nid]);
debug_assert!(self.nodes[nid].kind != Kind::Phi || self.nodes[nid].ty != ty::Id::VOID);
regalloc2::VReg::new(nid as _, regalloc2::RegClass::Int)
}
@ -953,15 +953,18 @@ impl<'a> Function<'a> {
}
Kind::Stck | Kind::Arg
if node.outputs.iter().all(|&n| {
matches!(self.nodes[n].kind, Kind::Stre | Kind::Load
if self.nodes[n].ty.loc(self.tys) == Loc::Reg)
|| matches!(self.nodes[n].kind, Kind::BinOp { op: TokenKind::Add }
if self.nodes.is_const(self.nodes[n].inputs[2])
&& self.nodes[n]
.outputs
.iter()
.all(|&n| matches!(self.nodes[n].kind, Kind::Stre | Kind::Load
if self.nodes[n].ty.loc(self.tys) == Loc::Reg)))
matches!(self.nodes[n].kind, Kind::Load
if self.nodes[n].ty.loc(self.tys) == Loc::Reg)
|| matches!(self.nodes[n].kind, Kind::Stre
if self.nodes[n].ty.loc(self.tys) == Loc::Reg
&& self.nodes[n].inputs[1] != nid)
|| matches!(self.nodes[n].kind, Kind::BinOp { op: TokenKind::Add }
if self.nodes.is_const(self.nodes[n].inputs[2])
&& self.nodes[n]
.outputs
.iter()
.all(|&n| matches!(self.nodes[n].kind, Kind::Stre | Kind::Load
if self.nodes[n].ty.loc(self.tys) == Loc::Reg)))
}) => self.nodes.lock(nid),
Kind::Stck if self.tys.size_of(node.ty) == 0 => self.nodes.lock(nid),
Kind::Stck => {