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
go version
$ go version go version devel +323212b Sun Jun 9 16:23:11 2019 +0000 linux/amd64
Yes.
I compiled the following function:
func f1(x int, b bool) int { if b { return x } return x }
I expected it to be compiled to a move and a return, given that the return value is always the same.
Instead, it was compiled to:
movblzx "".b+16(SP), AX testb AL, AL jeq f1_pc20 movq "".x+8(SP), AX movq AX, "".~r2+24(SP) ret f1_pc20: movq "".x+8(SP), AX movq AX, "".~r2+24(SP) ret
I think the compiler should recognize both cases to be the same.
Note: if this function is called from another one, the optimization is applied. For example:
func f2(x int, b bool) int { return f1(x, b) }
is compiled to
movq "".x+8(SP), AX movq AX, "".~r2+24(SP) ret
The text was updated successfully, but these errors were encountered:
Yep, this is a TODO. I even have a CL for it: https://go-review.googlesource.com/c/go/+/33634 I never got around to actually finishing it up.
Sorry, something went wrong.
Is the underlying issue different than the split/common approach in your CL? That seems a late stage remedy to what should already have been rewritten away by a "Moot Code Elimination" pass.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
I compiled the following function:
What did you expect to see?
I expected it to be compiled to a move and a return, given that the return value is always the same.
What did you see instead?
Instead, it was compiled to:
I think the compiler should recognize both cases to be the same.
Note: if this function is called from another one, the optimization is applied. For example:
is compiled to
The text was updated successfully, but these errors were encountered: