-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: inefficient assembly code generated by simple loop&branch code #48882
Comments
This is probably the register allocator making a nonoptimal choice. There's a phi operation which is merging The real question is why this code isn't generating conditional moves. Looks like branchelim doesn't quite work because prove has left some dead code around that confuses branchelim. Hmmm... |
@randall77 thx for answering, it helps me a lot. If i rewrite the code like this, it will be OK. func test_loop2(arr []int) (resp int) { max := 0 for i := 0; i < len(arr); i++ { if (arr[i] <= max) { continue } max = arr[i] } return max } The problematic code ssa.html -> What confuses me is that,these two codes are almost the same in the schedule phase. Why are different registers allocated during the RegAlloc phase? |
The only method I've found that consistently generates conditional moves is to use a helper function.
|
Change https://golang.org/cl/360674 mentions this issue: |
Complete comparison of results after applying CL https://golang.org/cl/360674 compilation for go binary itself:
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?centos8 & amd64
What did you do?
Given the code:
What did you expect to see?
What did you see instead?
The above assembly code has 2 more invalid move operations than the first code. Can someone help explain the reason?
The text was updated successfully, but these errors were encountered: