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: don't copy static array in range statement #15812

randall77 opened this issue May 24, 2016 · 0 comments


Copy link

@randall77 randall77 commented May 24, 2016

func f() {
    for _, b := range [...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {

The compiled code starts off with copying the static array to the stack, then using the stack copy to do the iteration. The static data is read-only, we could use the static data directly.

    0x0013 00019 (tmp1.go:4)    MOVQ    "".statictmp_1(SB), AX
    0x001a 00026 (tmp1.go:4)    MOVQ    "".statictmp_1+2(SB), CX
    0x0021 00033 (tmp1.go:4)    MOVQ    AX, "".autotmp_3+30(SP)
    0x0026 00038 (tmp1.go:4)    MOVQ    CX, "".autotmp_3+32(SP)
    0x002b 00043 (tmp1.go:4)    MOVQ    $0, AX
    0x002d 00045 (tmp1.go:4)    LEAQ    "".autotmp_3+30(SP), CX
    ...use CX to load the bytes...
@randall77 randall77 added this to the Go1.8 milestone May 24, 2016
@quentinmit quentinmit added the NeedsFix label Oct 11, 2016
@rsc rsc modified the milestones: Go1.9Early, Go1.8 Oct 21, 2016
@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.9Early May 3, 2017
@bradfitz bradfitz modified the milestones: Go1.10Early, Go1.10 Jun 14, 2017
@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 28, 2017
@bradfitz bradfitz modified the milestones: Go1.11, Go1.12, Unplanned May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.