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: delete the folded constants #530

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

constant folding: delete the folded constants #530

hugomg opened this issue Apr 28, 2022 · 0 comments

Comments

@hugomg
Copy link
Member

hugomg commented Apr 28, 2022

Currently, the constant folding pass replaces the use of a constant, but leaves the original definition of the constant. For example, consider the following program:

local m = {}

local PI = 3.14

function m.area(r: float): float
    return PI*r*r
end

return m

If we look at the generated IR, we can see that the main function still has an useless x1<-3.14 definition. This is dead code and might be confusing to users because it looks like the the constant folding didn't happen, even though it did.

function main() {
    x1 <- 3.14
    x2 <- NewClosure(f2)
    x2.upvalues <-
    x3 <- NewTable(1)
    CheckGC()
    x3["area"] <- x2
    return x3
}
function f2(x1) {
    x3 <- 3.14 * x1
    x2 <- x3 * x1
    return x2
}
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

1 participant