Ask questionscmd/compile: incomplete dead code elimination for conditional
go version)?<pre> $ go version go version devel +0dd120d Sun Aug 18 01:16:33 2019 +0000 linux/amd64 </pre>
Yes.
I compiled the following function and inspected the generated assembly (https://godbolt.org/z/q8MXUH):
func f(x string) int {
var y int
if x == "1" && len(x) == 2 {
y = 1
}
return y
}
I expected the generated code to be a simple return, as in this case: https://godbolt.org/z/o3uNbH.
movq $0, "".~r1+24(SP)
ret
Instead, the generated code contains a redundant ´jump´ instruction:
movq "".x+16(SP), AX
cmpq AX, $1
jne f_pc11
f_pc11:
pcdata $1, $2
xorps X0, X0
movups X0, "".~r1+24(SP)
ret
The same happens for this function https://godbolt.org/z/tDm4z2.
Answer
questions
erifan
This CL https://go-review.googlesource.com/c/go/+/239457 seems to help this issue.
Related questions