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: stringtoslicebytetmp optimization broken #14973

Closed
mdempsky opened this issue Mar 26, 2016 · 4 comments
Closed

cmd/compile: stringtoslicebytetmp optimization broken #14973

mdempsky opened this issue Mar 26, 2016 · 4 comments
Milestone

Comments

@mdempsky
Copy link
Member

cmd/compile is emitting calls to runtime.stringtoslicebyte when it could/should be using runtime.stringtoslicebytetmp instead:

$ cat sum.go
package f

func sum(s string) byte {
        var x byte
        for _, c := range []byte(s) {
                x += c
        }
        return x
}

$ go tool compile -S sum.go | grep stringtoslice
        0x0030 00048 (sum.go:5) CALL    runtime.stringtoslicebyte(SB)
        rel 49+4 t=6 runtime.stringtoslicebyte+0

Noticed during review of CL 21173.

@mdempsky mdempsky added this to the Go1.7 milestone Mar 26, 2016
@mdempsky
Copy link
Member Author

Seems broken in Go 1.6 too.

@gopherbot
Copy link

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

@mdempsky
Copy link
Member Author

Hrm, there's actually already a regress test for this in runtime_test.go: https://github.com/golang/go/blob/master/src/runtime/string_test.go#L223

Why isn't it failing?

/cc @dvyukov @randall77

@mdempsky
Copy link
Member Author

To answer my own question, TestCompareTempString and TestRangeStringCast were both using test strings short enough to fit into the 32-byte tmpBuf stack storage, so they weren't testing the intended compiler optimizations.

On the upside, TestCompareTempString's optimization was already working correctly.

@golang golang locked and limited conversation to collaborators Mar 27, 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

2 participants