-
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: use branchless instructions for simple conditionals #11813
Comments
You didn't state the compiler version. I recall work on this happening in Go 1.5. |
Just tried it on Go1.5beta2, and it still produces that output. |
/cc @randall77 @josharian @tzneal for SSA stuff. |
This optimization probably won't happen in the first release of SSA, but it is on the radar. |
Is SSA smart enough to do this yet? |
Yes, in some cases. |
I've seen some rewrite added to handle specific cases, but as of 3a90728, all of the examples I listed still include a branch. |
Most cases like this are not handled yet. Here's one which is:
|
It seems finicky. That example is logically identical to my func btoi(b bool) int {
if b {
return 1
}
return 0
} Yet my version doesn't benefit from the optimization :( |
@dsnet, known. See https://golang.org/cl/22711 and a25a7ad which uses it. Also, this is kinda a dup of #6011 |
Closing as dup of #6011. |
When I compile the following:
I notice the following output:
The compiled program uses the JGE and JEQ instruction to branch when it is possible to compile the above functions without branches.
This optimization is useful in situations where the conditional is not easily predictable, leading to poor branch predictor performance.
I'm using Go1.5beta2
The text was updated successfully, but these errors were encountered: