-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
What version of Go are you using (go version
)?
$ go version go version go1.11.4 windows/amd64
Does this issue reproduce with the latest release?
Yes. I tried on tip and the same happens.
What did you do?
I compiled the following code and inspected the assembly instructions generated by the compiler:
func test(slc [][]int) (int, int) {
var lentotal, lenslc int
for _, x := range slc {
lentotal += len(x)
lenslc++
}
return lentotal, lenslc
}
Assembly code generated:
- Version 1.10.1: https://godbolt.org/z/yWzkup
- Version 1.11 and tip: https://godbolt.org/z/zdJKsA
What did you expect to see?
I expected the compiler to generate code similar to the 1.10.1 version, because on tip it generates unnecessary jumps and an extra block of XOR's.
What did you see instead?
Instead, the compiler generated more code than what is necessary.
In the 1.10.1 version, the only thing that I think could be different is that, on line 5, the slice address is moved to CX, but it might not be necessary in the case that len(slc) is 0, which is well handled on tip.
Summing up, I believe the code should look something like:
pcdata $2, $0
pcdata $0, $0
xorl DX, DX
xorl BX, BX
movq "".slc+16(SP), AX
testq AX, AX
jle test_pc37
pcdata $2, $1
pcdata $0, $1
movq "".slc+8(SP), CX
jmp test_pc25
test_pc21:
addq $24, CX
test_pc25:
addq 8(CX), BX
incq DX
cmpq DX, AX
jlt test_pc21
test_pc37:
pcdata $2, $0
movq BX, "".~r1+32(SP)
movq DX, "".~r2+40(SP)
ret
Regarding the test_pc21 block, it could disappear, as is done in the 1.10.1 version.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
Status
Done