You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var sink []V
func main() {
sink = []V{
- (*tar.Reader)(nil),+ VOf((*tar.Reader)(nil)),
}
}
type V = interface{}
func VOf(t interface{}) V { return t }
The VOf function is a trivially useless function does nothing. If VOf function is missing, the main function is 176 bytes long, but if it is present, the function is 188 bytes long.
This is no longer directly a bug at tip, because we are smarter about generating nil using MOVQ $0, ... instead of MOVQ "".statictmp_0(SB), AX ; MOVQ AX, .... (CL 141118)
The reason the temp was used is that the compiler didn't realize the load (of 0) could not be reordered with the newobject call. So the value needed to be loaded, spilled, restored, and then put in the desired destination.
then an autotmp is used, because the compiler doesn't know that newobject won't modify tr.
We could teach the compiler that newobject won't modify globals, but the compiler doesn't have any infrastructure for taking advantage of that knowledge. Yet.
I'm going to close this as fixed. The more general case will probably be solved if and when we do some sort of alias analysis in the compiler.
Using
go1.11.2
.Consider the following snippet:
The
VOf
function is a trivially useless function does nothing. IfVOf
function is missing, the main function is 176 bytes long, but if it is present, the function is 188 bytes long.The assembly output without use of
VOf
is:However, calling
VOf
results in the generation of anautotmp
variables.An additional
autotmp
variable is added for every element in the slice, so large slice literals are noticeably more bloated withVOf
than without.The text was updated successfully, but these errors were encountered: