cmd/compile: detect and apply more CMOV optimizations #27780
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?go version go1.11 linux/amd64
Does this issue reproduce with the latest release?
Yes. And checked with master as of (go version devel +7f3de1f275 Thu Sep 20 14:44:04 2018 +0530 linux/amd64)
What operating system and processor architecture are you using (
go env
)?What did you do?
Consider this code -
What did you expect to see?
Here, both functions are trying to get the min of 3 integers, albeit in slightly different manners. First one performs min of 2 integers twice, second one performs them in a single function. One would think that the compiler would be smart enough so that the generated code would be equivalent. Or atleast, not be 14% faster than the other.
What did you see instead?
But on investigating the assembly, we see interesting results
Notice that there is no CMOV generated in the 2nd case.
Only if we change the min3 code to behave like min2 like this -
then we get CMOV generated. But this is only after I realized how the compiler is converting the code to explicitly generate the CMOV instruction.
Originally discussed in a golang-dev thread here - https://groups.google.com/forum/#!topic/golang-dev/JaYi4D-tsbY.
/cc @randall77 @rasky
The text was updated successfully, but these errors were encountered: