]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: undo special handling of zero-valued STRUCTLIT
authorCherry Zhang <cherryyz@google.com>
Tue, 14 Feb 2017 16:01:04 +0000 (11:01 -0500)
committerCherry Zhang <cherryyz@google.com>
Tue, 14 Feb 2017 18:57:56 +0000 (18:57 +0000)
CL 35261 introduces special handling of zero-valued STRUCTLIT for
efficient struct zeroing. But it didn't cover all use cases, for
example, CONVNOP STRUCTLIT is not handled.

On the other hand, CL 34566 handles zeroing earlier, so we don't
need the change in CL 35261 for efficient zeroing. Other uses of
zero-valued struct literals are very rare. So undo the change in
walk.go in CL 35261.

Add a test for efficient zeroing.

Fixes #19084.

Change-Id: I0807f7423fb44d47bf325b3c1ce9611a14953853
Reviewed-on: https://go-review.googlesource.com/36955
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/asm_test.go
src/cmd/compile/internal/gc/walk.go
test/fixedbugs/issue19084.go [new file with mode: 0644]

index 7cffae0e5fc0ae90bf8139981bfe44f25051b805..4373cfa6b62fde9912f97092e15329b0851b257c 100644 (file)
@@ -314,6 +314,17 @@ func f(t *T) {
                []string{"\tMOVQ\t\\$0, \\(.*\\)", "\tMOVQ\t\\$0, 8\\(.*\\)", "\tMOVQ\t\\$0, 16\\(.*\\)"},
        },
        // TODO: add a test for *t = T{3,4,5} when we fix that.
+       // Also test struct containing pointers (this was special because of write barriers).
+       {"amd64", "linux", `
+type T struct {
+       a, b, c *int
+}
+func f(t *T) {
+       *t = T{}
+}
+`,
+               []string{"\tMOVQ\t\\$0, \\(.*\\)", "\tMOVQ\t\\$0, 8\\(.*\\)", "\tMOVQ\t\\$0, 16\\(.*\\)", "\tCALL\truntime\\.writebarrierptr\\(SB\\)"},
+       },
 
        // Rotate tests
        {"amd64", "linux", `
index bf7f253517f83af7f825fdb267e1792fb8df3634..28b430f22dd307d8c0995d17091dd9c4c0819561 100644 (file)
@@ -1539,9 +1539,6 @@ opswitch:
                n = r
 
        case OARRAYLIT, OSLICELIT, OMAPLIT, OSTRUCTLIT, OPTRLIT:
-               if n.Op == OSTRUCTLIT && iszero(n) && !instrumenting { // TODO: SSA doesn't yet handle ARRAYLIT with length > 1
-                       break
-               }
                if isStaticCompositeLiteral(n) {
                        // n can be directly represented in the read-only data section.
                        // Make direct reference to the static data. See issue 12841.
diff --git a/test/fixedbugs/issue19084.go b/test/fixedbugs/issue19084.go
new file mode 100644 (file)
index 0000000..ba53063
--- /dev/null
@@ -0,0 +1,17 @@
+// compile
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 19084: SSA doesn't handle CONVNOP STRUCTLIT
+
+package p
+
+type T struct {
+       a, b, c, d, e, f, g, h int // big, not SSA-able
+}
+
+func f() {
+       _ = T(T{})
+}