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: eliminate write barriers for ... args #14263

Closed
randall77 opened this issue Feb 8, 2016 · 2 comments
Closed

cmd/compile: eliminate write barriers for ... args #14263

randall77 opened this issue Feb 8, 2016 · 2 comments

Comments

@randall77
Copy link
Contributor

Consider the following example:

//go:noescape
func f(a ...*int)
func g(x, y *int) {
    f(x, y)
}

This gets compiled to something like this:

func g(x, y *int) {
    var a [2]*int
    var b = a[:]
    b[0] = x
    b[1] = y
    f(b)
}

The compiler thinks the assignments b[0]=x and b[1]=y need a write barrier because it doesn't know that b points to the stack. If instead we compiled those assignments as a[0]=x and a[0]=y, then the compiler does know that they are on the stack and will elide the write barriers.

Or maybe we could somehow deduce that b always points to the stack? That seems harder.

This problem happens all the time with a ...{}interface, for instance with fmt.Printf args. I'm not sure how much it matters speed-wise, but I suspect this would save a chunk of code size.

@RLH @aclements @rsc

@randall77 randall77 added this to the Go1.7 milestone Feb 8, 2016
@rsc
Copy link
Contributor

rsc commented Feb 9, 2016

The real issue here is that b exists at all. The generated code should look like

var a [2]*int
a[0] = x
a[1] = y
f(a[:])

That would probably eliminate some LEAQ and unnecessary address arithmetic too.

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Apr 24, 2017
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

3 participants