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: redundant nil check calling promoted method #17242

Closed
mdempsky opened this issue Sep 26, 2016 · 1 comment
Closed

cmd/compile: redundant nil check calling promoted method #17242

mdempsky opened this issue Sep 26, 2016 · 1 comment

Comments

@mdempsky
Copy link
Member

Compiling this source:

package p

type scanner struct {
    source
}

func (s *scanner) ident() {
    s.startLit()
}

type source struct {
    buf [4<<10]byte
    suf, r0 int
    lit []byte
}

func (s *source) startLit() {
    s.suf = s.r0
    s.lit = s.lit[:0]
}

produces this compiled function:

"".(*scanner).ident t=1 size=35 args=0x8 locals=0x0
    0x0000 00000 (repro.go:7)       TEXT    "".(*scanner).ident(SB), $0-8
    0x0000 00000 (repro.go:7)       FUNCDATA        $0, gclocals·87d20ce1b58390b294df80b886db78bf(SB)
    0x0000 00000 (repro.go:7)       FUNCDATA        $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
    0x0000 00000 (repro.go:8)       MOVQ    "".s+8(FP), AX
    0x0005 00005 (repro.go:8)       TESTB   AL, (AX)
    0x0007 00007 (repro.go:8)       TESTB   AL, (AX)
    0x0009 00009 (repro.go:8)       MOVQ    4104(AX), CX
    0x0010 00016 (repro.go:8)       MOVQ    CX, 4096(AX)
    0x0017 00023 (repro.go:8)       MOVQ    $0, 4120(AX)
    0x0022 00034 (repro.go:9)       RET

The second TESTB instruction is unnecessary.

/cc @randall77

@gopherbot
Copy link

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

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