Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoisting of loop-invariant subexpressions #3195

Merged
merged 19 commits into from
Dec 3, 2024
Merged

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Nov 27, 2024

f a (\{ x1 .. xk := body }) a'

where f is a recursive function which does not modify its function argument (the one for which a lambda is provided), i.e., passes it to recursive invocations unchanged (it's the second argument in the above example). A function f satisfying this requirement implements some kind of loop with the lambda-expression usually being the loop body / action.

Let e.g. body = g x1 .. xk b1 b2 where b1, b2 do not contain any variables bound in the lambda (x1,..,xk). If b1, b2 are non-trivial (require computation), then these loop-invariant subexpressions are hoisted outside of the loop, obtaining:

let 
  y1 := b1;
  y2 := b2;
in
f a (\{ x1 .. xk := g x1 .. xk y1 y2) a'
  • Adds a volatility info in Core which prevents the lets created by loop-invariant expression hoisting from being folded back.
  • Removes potential duplication in the specialization optimization.
  • Adds another optimization phase before lambda-lifting where hoisting of loop-invariant subexpressions is performed. This allows to reduce the number of iterations in the main optimization phase after lambda-lifting.

@lukaszcz lukaszcz added enhancement New feature or request core Related to JuvixCore optimization labels Nov 27, 2024
@lukaszcz lukaszcz added this to the 0.6.9 milestone Nov 27, 2024
@lukaszcz lukaszcz self-assigned this Nov 27, 2024
@lukaszcz lukaszcz force-pushed the loop-invariant-code-motion branch 2 times, most recently from 998cd8f to 80dd864 Compare November 28, 2024 18:41
@lukaszcz lukaszcz force-pushed the loop-invariant-code-motion branch from ed93261 to ceed253 Compare November 29, 2024 11:27
@lukaszcz lukaszcz marked this pull request as ready for review November 29, 2024 11:35
@lukaszcz lukaszcz merged commit 7db7444 into main Dec 3, 2024
4 checks passed
@lukaszcz lukaszcz deleted the loop-invariant-code-motion branch December 3, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to JuvixCore enhancement New feature or request optimization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lift complex expression that don't use the lambda-bound variables out of the lambdas
2 participants