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

constant folding: fold non-trivial constants #531

Open
hugomg opened this issue Apr 28, 2022 · 3 comments
Open

constant folding: fold non-trivial constants #531

hugomg opened this issue Apr 28, 2022 · 3 comments

Comments

@hugomg
Copy link
Member

hugomg commented Apr 28, 2022

It would be nice if our constant folding pass could propagate things that aren't constant literals. For example:

local PI = 3.14
local TAU = 2*PI

function m.f()
   -- something using TAU
end
@srijan-paul
Copy link
Member

This kind of constant folding should come after constant propagation, no?

@hugomg
Copy link
Member Author

hugomg commented Apr 29, 2022

I think it might want to interleave them. First we constant fold the outermost function. Then, we look at all the initUpvales inside it and see which ones are constant and propagate those constants into the inner functions. Then we repeat the process for the inner functions.

@srijan-paul
Copy link
Member

Makes sense. Perhaps we do N passes until no more constants can be propagated / folded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants