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

Closed
mariecurried opened this issue Jun 14, 2019 · 5 comments
Closed

cmd/compile: multiple ineffective assignments #32624

mariecurried opened this issue Jun 14, 2019 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@mariecurried
Copy link

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 14, 2019
@FiloSottile FiloSottile added this to the Unplanned milestone Jun 14, 2019
@FiloSottile
Copy link
Contributor

/cc @randall77

@randall77
Copy link
Contributor

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

@mariecurried
Copy link
Author

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.

@mariecurried
Copy link
Author

mariecurried 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
@mariecurried
Copy link
Author

No longer reproduces

@golang golang locked and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
None yet
Development

No branches or pull requests

4 participants