-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: elimination of unused runtime calls #17216
Comments
This is mostly fixed on tip. It now compiles to:
This is mostly due to https://go-review.googlesource.com/c/29373/ which inlines convT2E. |
Thanks @randall77 - yes, the current tip seems to be optimizing that. However if I change function signature from https://play.golang.org/p/KYp1jVhTvj results become less appealing (compiled using current tip):
And there is also map[type]type case (also compiled using current tip):
As far as I could tell - map doesn't have any "side effects" with user code (it's not truly side effect free tho), so if map is unused, it's creation can be eliminated if no functions were called during map creation. Same goes for Or am I missing something here? Should I open another issue, btw? |
No, we can use this one. I'll update the title to be more descriptive of the existing suboptimal code. |
Looks as though gccgo "-O" has issues as well (deletes the call but not the allocations). |
The original repro is now fixed as of CL 38746. This issue is now solely about eliminating runtime calls whose results are not used. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7.1 windows/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
Compiled simple program with two unused parameters of type
interface{}
and empty body.https://play.golang.org/p/TkLKdhLcXo
What did you expect to see?
Dead code elimination removing the call to
empty
and any unnecessary conversions.What did you see instead?
The call to
empty
was removed, but conversions are left around:Same thing happen with parameters of map[type]type. With parameter of
...interface{}
theempty
function itself doesn't get optimized away.While it's not a bug, it can be a handy feature for debug prints that get optimized away if build tag doesn't present.
The text was updated successfully, but these errors were encountered: