Ask questionscmd/compile: incomplete dead code elimination for conditional

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

<pre> $ go version go version devel +0dd120d Sun Aug 18 01:16:33 2019 +0000 linux/amd64 </pre>

Does this issue reproduce with the latest release?


What did you do?

I compiled the following function and inspected the generated assembly (

func f(x string) int {
    var y int
    if x == "1" && len(x) == 2 {
        y = 1

    return y

What did you expect to see?

I expected the generated code to be a simple return, as in this case:

        movq    $0, "".~r1+24(SP)

What did you see instead?

Instead, the generated code contains a redundant ´jump´ instruction:

        movq    "".x+16(SP), AX
        cmpq    AX, $1
        jne     f_pc11
        pcdata  $1, $2
        xorps   X0, X0
        movups  X0, "".~r1+24(SP)

The same happens for this function


Answer questions erifan

This CL seems to help this issue.


Related questions

cmd/link: segmentation fault during mach-o linking hot 6
cmd/vet: potential false positive in the "suspect or" check hot 4
cmd/go: cannot find module providing package error stops `go get` processing hot 3
vendor/ undefined: errors.Frame ... hot 2
cmd/cgo error: runtime: unknown pc 0x7fff5c805b86 hot 2
runtime: crash with "invalid pc-encoded table" hot 2
internal/poll: transparently support new linux io_uring interface hot 2
crypto/x509: 'certificate signed by unknown authority' on mipsle hot 2
x/tools/cmd/gopls: "build cache is required, but could not be located: GOCACHE is not defined and $HOME is not defined" hot 2
Plis fixit! Its not good!!! hot 2
cmd/go: needs a better error than "missing dot in first path element" when GOROOT is set incorrectly hot 2
encoding/json: invalid use of ,string struct tag, trying to unmarshal "" into int hot 2
Golang show warning after updating to 1.13 on OSX Catalina 10.15 hot 2
x/mobile: gomobile bind is failing with latest version [+cafc553] of gomobile hot 2
cmd/go: "found, but does not contain package" error refers to replaced version instead of its replacement hot 2
Github User Rank List