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

cmd/compile: avoid dead code in escape analysis #16871

Closed
dsnet opened this issue Aug 25, 2016 · 7 comments
Closed

cmd/compile: avoid dead code in escape analysis #16871

dsnet opened this issue Aug 25, 2016 · 7 comments

Comments

@dsnet
Copy link
Member

dsnet commented Aug 25, 2016

Using go1.7

Consider the following function:

func Foo(codes []int) int {
    const debug = false
    if debug && !sort.IntsAreSorted(codes) {
        panic("input slice is not sorted")
    }

    var s int
    for _, i := range codes {
        s += i
    }
    return s
}

Currently, codes escapes to the heap. I expect it to not escape since the function where it does escape sort.IntsAreSorted is dead. (the fact that codes escapes at all in sort.IntsAreSorted is a separate concern).

/cc @dr2chase

@dsnet dsnet added this to the Unplanned milestone Aug 25, 2016
@josharian
Copy link
Contributor

Ordering the many compiler stages is a tricky problem. It'd also be nice for dead code not to count against a function's budget for inlining. It might be nice to add an early, crude deadcode pass, which implies also doing a bunch of constant folding. And we'd need to make sure all code gets typechecked, dead or not.

@navytux
Copy link
Contributor

navytux commented Jan 31, 2017

Looks to be the same as #12397.

@minux
Copy link
Member

minux commented Feb 1, 2017 via email

@dr2chase
Copy link
Contributor

dr2chase commented Feb 1, 2017

Right now DCE is in SSA and SSA uses results of escape analysis, so that's moderately tricky. We would need an even-more-generic form of SSA that was (initially) agnostic about whether things were heap or stack allocated.

@minux
Copy link
Member

minux commented Feb 1, 2017 via email

@randall77
Copy link
Contributor

randall77 commented Feb 1, 2017 via email

@gopherbot
Copy link

CL https://golang.org/cl/37508 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants