Skip to content

Commit

Permalink
boots: Start removing duplicate stores as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Oct 27, 2024
1 parent 31b3d24 commit 2fb7d3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkgs/boots/load_elimination.dora
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,22 @@ pub fn performLoadElimination(ci: CompilationInfo, graph: Graph) {
if inst.hasClassInfo() {
let class_info = inst.getClassInfo();
let field_offset = inst.getOffset();

let object = inst.getInput(0).getValue();
let field = Field(object, class_info, field_offset);
let cur_value = data.class_values.get(field);

data.class_values.retainIf(|field: Field, value: Inst|: Bool {
field.class_info != class_info || field.offset != field_offset
});

let new_value = inst.getInput(1).getValue();
if cur_value is Some(cur_value) && cur_value == new_value {
assert(!inst.hasUses());
inst.remove();
}

data.class_values.insert(field, new_value);
}

} else if op.isCall() {
Expand Down
11 changes: 11 additions & 0 deletions tests/opt/load-elimination.dora
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ fn main() {

let x = Foo(100, 300);
assert(f3(x, x) == 200);

let x = Foo(100, 300);
assert(f4(x, 12) == 12);
}

@Optimize
Expand All @@ -34,3 +37,11 @@ fn f3(foo: Foo, foo2: Foo): Int {
foo2.b = 10;
x + foo.a
}

@Optimize
fn f4(foo: Foo, value: Int): Int {
let tmp = foo.a;
foo.a = value;
foo.a = value;
foo.a
}

0 comments on commit 2fb7d3d

Please sign in to comment.