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: ineffective branch caused by defer #32930

Open
marigonzes opened this issue Jul 3, 2019 · 2 comments

Comments

Projects
None yet
4 participants
@marigonzes
Copy link

commented Jul 3, 2019

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

$ go version
go version devel +d410642 Mon Jul 1 21:30:23 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

I was testing the behavior of defer, so I ended up compiling the following functions (https://godbolt.org/z/uALdNA):

package test

func f() {
}

func usef() {
    defer f()
}

What did you expect to see?

I expected the generated assembly to not contain any unnecessary branches.

What did you see instead?

Instead, there is a repeated block of instructions that is preceded by a condicional jump (https://godbolt.org/z/uALdNA):

        testl   AX, AX
        jne     applyf_pc83
        xchgl   AX, AX
        call    runtime.deferreturn(SB)
        movq    64(SP), BP
        addq    $72, SP
        ret
applyf_pc83:
        xchgl   AX, AX
        call    runtime.deferreturn(SB)
        movq    64(SP), BP
        addq    $72, SP
        ret
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 3, 2019

@dmitshur dmitshur added this to the Go1.14 milestone Jul 4, 2019

@randall77

This comment has been minimized.

Copy link
Contributor

commented Jul 4, 2019

This is known. One return path is the normal return path, and one is the panic/recover return path. Each has a call to deferreturn. We don't share epilogues at the moment, see #24936 for some discussion.

In any case, this bug will probably become obsolete once we fix #14939.

But I'll leave this open for now. I couldn't find an issue explicitly about epilogue sharing (which this is), so might as well use this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.