Skip to content

Commit

Permalink
dfmc-optimization: Fix missed if-computation optimizations
Browse files Browse the repository at this point in the history
These changes fix missed cases where type-constrained values in if
tests and instance? tests were substituted in the left (consequent)
side of the if body computations, but not in the left side of the if
merge.

* sources/dfmc/optimization/assignment.dylan
  (maybe-rename-temporaries-in-conditional): Substitute the
   type-constrained value when the <if> test value appears in the left
   side of the <if-merge>.

* sources/dfmc/optimization/calls.dylan
  (do-optimize-instance?-user): Substitute the type-constrained value
   when the <if> instance? test value appears in the left side of the
   <if-merge>.
  • Loading branch information
housel committed Jun 19, 2024
1 parent 5777cfb commit 338eb33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions sources/dfmc/optimization/assignment.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,20 @@ define method maybe-rename-temporaries-in-conditional
(c.environment, <constrain-type>,
value: to-be-renamed, type: constraint);
let then-f = c.consequent;
let merge-c :: <if-merge> = c.next-computation;
let changed? = #f;
rename-temporary!(to-be-renamed, tt-t);
for-computations(tc from then-f before c.next-computation)
for-computations(tc from then-f before merge-c)
let now-changed? = rename-temporary-references!(tc, to-be-renamed, tt-t);
changed? := (changed? | now-changed?);
end;
// The left side of the merge is also part of the consequent
if (merge-c.merge-left-value == to-be-renamed)
merge-replace-left-value!(merge-c, to-be-renamed, tt-t);
changed? := #t;
end;
if (changed?)
insert-computation-before!(then-f, tt-c);
insert-computation-before-reference!(then-f, tt-c, tt-t);
else // It's not used in the consequent, so get rid of it.
remove-user!(to-be-renamed, tt-c);
end;
Expand Down
10 changes: 8 additions & 2 deletions sources/dfmc/optimization/calls.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ define method do-optimize-instance?-user(c :: <if>, object, type) => ();
= make-with-temporary(c.environment, <constrain-type>,
value: object, type: type);
let then-f = c.consequent;
let merge-c :: <if-merge> = c.next-computation;
let changed? = #f;
for-computations(tc from then-f before c.next-computation)
for-computations(tc from then-f before merge-c)
let now-changed? = rename-temporary-references!(tc, object, tt-t);
changed? := (changed? | now-changed?);
end;
// The left side of the merge is also part of the consequent
if (merge-c.merge-left-value == object)
merge-replace-left-value!(merge-c, object, tt-t);
changed? := #t;
end;
if (changed?)
insert-computation-before!(then-f, tt-c);
insert-computation-before-reference!(then-f, tt-c, tt-t);
else // It's not used in the consequent, so get rid of it.
remove-user!(object, tt-c);
end
Expand Down

0 comments on commit 338eb33

Please sign in to comment.