fixing nasty aclass clobber priority bug

This commit is contained in:
Jakub Doka 2024-11-10 18:56:33 +01:00
parent 1e02efc1eb
commit 335e6ec20a
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 35 additions and 38 deletions

View file

@ -614,23 +614,40 @@ main := fn(): uint {
#### storing_into_nullable_struct #### storing_into_nullable_struct
```hb ```hb
StructA := struct {b: StructB}
StructB := struct {c: uint}
optionala := fn(): ?StructA {
return .(.(1))
}
Struct := struct {inner: uint} Struct := struct {inner: uint}
optional := fn(): ?Struct { optional := fn(): ?Struct {
return .(10) return .(10)
} }
do_stuff := fn(arg: Struct): uint { do_stuff := fn(arg: uint): uint {
return arg.inner return arg
} }
main := fn(): void { main := fn(): uint {
val := optional() a := optionala()
if val == null { if a == null {
return return 10
} }
val.inner = 100 a.b = .(0)
inner := do_stuff(val) innera := do_stuff(a.b.c)
//val := optional()
//if val == null {
// return 20
//}
//val.inner = 100
//inner := do_stuff(val.inner)
return innera
//+ inner
} }
``` ```

View file

@ -1267,8 +1267,8 @@ impl Nodes {
let &[ctrl, region, store] = self[target].inputs.as_slice() else { unreachable!() }; let &[ctrl, region, store] = self[target].inputs.as_slice() else { unreachable!() };
let load_range = range_of(self, region, self[target].ty, tys); let load_range = range_of(self, region, self[target].ty, tys);
let mut cursor = store;
let mut cursor = store;
while cursor != MEM && self[cursor].kind != Kind::Phi { while cursor != MEM && self[cursor].kind != Kind::Phi {
if self[cursor].inputs[0] == ctrl if self[cursor].inputs[0] == ctrl
&& self[cursor].inputs[2] == region && self[cursor].inputs[2] == region
@ -1279,9 +1279,9 @@ impl Nodes {
let range = range_of(self, self[cursor].inputs[2], self[cursor].ty, tys); let range = range_of(self, self[cursor].inputs[2], self[cursor].ty, tys);
if range.start >= load_range.end || range.end <= load_range.start { if range.start >= load_range.end || range.end <= load_range.start {
cursor = self[cursor].inputs[3]; cursor = self[cursor].inputs[3];
continue; } else {
break;
} }
break;
} }
if store != cursor { if store != cursor {
@ -2414,31 +2414,6 @@ impl<'a> Codegen<'a> {
let (value_index, value_region) = self.ci.nodes.aclass_index(value); let (value_index, value_region) = self.ci.nodes.aclass_index(value);
if value_index != 0 { if value_index != 0 {
self.ci.nodes[value_region].aclass = 0; self.ci.nodes[value_region].aclass = 0;
//// simply switch the class to the default one
//let aclass = &mut self.ci.scope.aclasses[value_index];
//self.ci.nodes.load_loop_aclass(value_index, aclass, &mut self.ci.loops);
//let last_store = aclass.last_store.get();
//let mut cursor = last_store;
//let mut first_store = cursor;
//while cursor != MEM {
// first_store = cursor;
// debug_assert_matches!(
// self.ci.nodes[cursor].kind,
// Kind::Stre,
// "{:?}",
// self.ci.nodes[cursor]
// );
// cursor = self.ci.nodes[cursor].inputs[3];
//}
//if last_store != MEM {
// let base_class = self.ci.scope.aclasses[0].last_store.get();
// if base_class != MEM {
// self.ci.nodes.modify_input(first_store, 3, base_class);
// }
// self.ci.scope.aclasses[0].last_store.set(last_store, &mut self.ci.nodes);
//}
self.ci.nodes.load_loop_aclass(0, &mut self.ci.scope.aclasses[0], &mut self.ci.loops); self.ci.nodes.load_loop_aclass(0, &mut self.ci.scope.aclasses[0], &mut self.ci.loops);
self.ci.nodes.load_loop_aclass( self.ci.nodes.load_loop_aclass(
value_index, value_index,
@ -2457,9 +2432,13 @@ impl<'a> Codegen<'a> {
let (index, _) = self.ci.nodes.aclass_index(region); let (index, _) = self.ci.nodes.aclass_index(region);
if self.ci.nodes[value].kind == Kind::Load { if self.ci.nodes[value].kind == Kind::Load {
let (lindex, _) = self.ci.nodes.aclass_index(self.ci.nodes[value].inputs[1]); let (lindex, ..) = self.ci.nodes.aclass_index(self.ci.nodes[value].inputs[1]);
let clobber = self.ci.scope.aclasses[lindex].clobber.get(); let clobber = self.ci.scope.aclasses[lindex].clobber.get();
self.ci.scope.aclasses[index].clobber.set(clobber, &mut self.ci.nodes); if self.ci.nodes.idepth(clobber)
> self.ci.nodes.idepth(self.ci.scope.aclasses[index].clobber.get())
{
self.ci.scope.aclasses[index].clobber.set(clobber, &mut self.ci.nodes);
}
} }
let aclass = &mut self.ci.scope.aclasses[index]; let aclass = &mut self.ci.scope.aclasses[index];
self.ci.nodes.load_loop_aclass(index, aclass, &mut self.ci.loops); self.ci.nodes.load_loop_aclass(index, aclass, &mut self.ci.loops);
@ -3948,6 +3927,7 @@ impl<'a> Codegen<'a> {
fn add_clobber_stores(&mut self, clobbered_aliases: BitSet) { fn add_clobber_stores(&mut self, clobbered_aliases: BitSet) {
for clobbered in clobbered_aliases.iter() { for clobbered in clobbered_aliases.iter() {
debug_assert_matches!(self.ci.nodes[self.ci.ctrl.get()].kind, Kind::Call { .. });
self.ci.scope.aclasses[clobbered].clobber.set(self.ci.ctrl.get(), &mut self.ci.nodes); self.ci.scope.aclasses[clobbered].clobber.set(self.ci.ctrl.get(), &mut self.ci.nodes);
} }
self.ci.nodes[self.ci.ctrl.get()].clobbers = clobbered_aliases; self.ci.nodes[self.ci.ctrl.get()].clobbers = clobbered_aliases;