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: multiple ineffective assignments #32624

Open
marigonzes opened this issue Jun 14, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@marigonzes
Copy link

commented Jun 14, 2019

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

$ go version
go version devel +73abea3 Thu Jun 13 02:49:03 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What did you do?

I compiled the following function and inspected the assembly code generated (https://godbolt.org/z/-7YwuJ):

func f() (ret int) {
    return func() int {
        ret = -1
        return 1
    }()
}

What did you expect to see?

I expected function f to be compiled to a simple move+return.

What did you see instead?

Instead, I see 3 moves before the return.

@FiloSottile FiloSottile added this to the Unplanned milestone Jun 14, 2019

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Jun 14, 2019

@randall77

This comment has been minimized.

Copy link
Contributor

commented Jun 14, 2019

Yep.
Might be related to #14762.

See cmd/compile/internal/gc/ssa.go:exit, the TODO about PPARAMOUTs.
Also cmd/compile/internal/gc/ssa.go:addNamedValue

@marigonzes

This comment has been minimized.

Copy link
Author

commented Jun 14, 2019

Something else I found while playing with this function is that if I assign to ret before the return, these assignments are not optimized away, as you can see in https://godbolt.org/z/wuO5-j.
This doesn't happen without the anonymous function call.

@marigonzes

This comment has been minimized.

Copy link
Author

commented Jun 15, 2019

These issues seem to be a regression caused by 0029cd4.
@dr2chase

@agnivade agnivade changed the title cmd/compile: multiple ineffective assignements cmd/compile: multiple ineffective assignments Jul 15, 2019

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.