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: unnecessary LoadReg #19666

Closed
cherrymui opened this issue Mar 23, 2017 · 2 comments
Closed

cmd/compile: unnecessary LoadReg #19666

cherrymui opened this issue Mar 23, 2017 · 2 comments

Comments

@cherrymui
Copy link
Member

What version of Go are you using (go version)?

tip (6f4a458)

Compile this code:

func f(a []int) {
        for i, x := range a {
                g(i, x)
        }
}

//go:noinline
func g(i, x int) {}

It generates

  b1:
    v1 = InitMem <mem>
    v29 = Arg <int> {a} [8] : a+8[int]
    v32 = Arg <*int> {a} : a[*int]
    v6 = LoadReg <int> v29 : AX
    v33 = TESTQ <flags> v6 v6
    GT v33 -> b2 b3 (likely)
  b2: <- b1
    v2 = SP <uintptr> : SP
    v28 = LoadReg <*int> v32 : CX
    v11 = MOVQconst <int> [0] : DX
    Plain -> b4
  b4: <- b2 b5
    v12 = Phi <*int> v28 v3 : CX
    v13 = Phi <mem> v1 v21
    v16 = Phi <int> v11 v17 : DX
    v30 = StoreReg <*int> v12 : .autotmp_5[*int]
    v23 = StoreReg <int> v16 : i[int]
    v15 = MOVQload <int> v12 v13 : BX
    v18 = MOVQstore <mem> v2 v16 v13
    v20 = MOVQstore <mem> [8] v2 v15 v18
    v21 = CALLstatic <mem> {"".g} [16] v20
    v26 = LoadReg <*int> v30 : AX
    v24 = ADDQconst <*int> [8] v26 : AX
    v19 = LoadReg <int> v23 : CX
    v27 = ADDQconst <int> [1] v19 : CX
    v5 = LoadReg <int> v29 : DX
    v7 = CMPQ <flags> v27 v5
    LT v7 -> b5 b3 (likely)
  b5: <- b4
    v17 = Copy <int> v27 : DX
    v3 = Copy <*int> v24 : CX
    v4 = LoadReg <int> v29 : AX     // <------ this
    Plain -> b4
  b3: <- b1 b4
    v31 = Phi <mem> v1 v21
    Ret v31

Note v4 loads a value in AX, but it is never used. It would be good not to generate this.

@cherrymui cherrymui added this to the Go1.9 milestone Mar 23, 2017
@randall77
Copy link
Contributor

Pretty sure this is a dup of #14761

@gopherbot
Copy link
Contributor

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

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

4 participants