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: SSA compiler removes code in benchmarks #14813
Comments
You are not using the value from popcnt2, and because the function was inlined, the compiler can see the value is unused, so it removed the call entirely. Here is something I wrote about writing a reliable benchmark, http://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go, hopefully it will be of use. I am going to close this as this is not a bug. For general Go questions see https://golang.org/wiki/Questions. Thanks! |
Huh, I've seen the Using the top-level result variable solves the problem. I guess it's kind of a documentation issue. Either way, thank you as well. |
@bradfitz I think we should reopen this issue, or replace it with another as a placeholder to double check that all the benchmarks in the stdlib are armoured against the improving abilities of the SSA backend. |
I've found a few cases of Could the problem be solved with something similar to |
No, no more magical //go:XXX comments please. It's beginning to sound like gcc's attribute, //go:do_not_optimize_this |
One major issue with this benchmark is that it uses the loop's index as an argument to the function. See the "Traps for young players" in this article: https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go. |
Go version:
go version devel +2dcbbbd Mon Mar 14 05:13:47 2016 +0000 linux/amd64
Go env:
This code is a simple benchmark of Hamming weight algorithms: http://play.golang.org/p/kOid3lX9Yz
In Go 1.6 running
go test popcnt_test.go -bench .
gives the result:But on tip with SSA turned on it's
Running with
-gcflags "-S"
confirms that the tip version completely removes the call to popcnt2. If I add//go:noinline
before popcnt2 definition, it works fine (although slower than 1.6 because it doesn't inline):Same goes for running with
-gcflags "-ssa=0"
, the call isn't removed.The text was updated successfully, but these errors were encountered: