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

$ go version
go version devel +c4f87ed Tue Mar 26 02:20:09 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

I was playing around with the compiler to see what code it would produce under various situations. After testing for a while, I found this case, where the code produced is a little weird:

package test

func test1() {
    return
}

func test2(k *int) {
    if k == nil {
        test1()
    }
}

What did you expect to see?

I expected the test2 function to compile to a simple return.

What did you see instead?

Instead, the following code was generated (notice the weird double jump):

        movq    "".k+8(SP), AX
        pcdata  $2, $0
        testq   AX, AX
        jeq     test2_pc11
test2_pc10:
        pcdata  $2, $-2
        pcdata  $0, $-2
        ret
test2_pc11:
        pcdata  $2, $0
        pcdata  $0, $1
        xchgl   AX, AX
        jmp     test2_pc10

Back in version go1.11, the code produced was a bare return, as I was initially expecting.

Comment From: randall77

This looks like the added inline mark prevents the removal of the branch. Inline marks are used to get correct backtraces during panics, even in the presence of inlining.

There's probably a way to remove unnecessary inline marks in cases like this.

Comment From: mariecurried

Bisected to 69c2c56, which makes sense.

Comment From: josharian

Possibly related: https://github.com/golang/go/issues/20354

Comment From: mariecurried

The code mentioned in this issue has been fixed by c46ebec. Should this remain open as an umbrella issue?