]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: don't use statictmps for SSA-able composite literals
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 10 May 2017 19:48:17 +0000 (12:48 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 11 May 2017 18:28:40 +0000 (18:28 +0000)
The writebarrier test has to change.
Now that T23 composite literals are passed to the backend,
they get SSA'd, so writes to their fields are treated separately,
so the relevant part of the first write to t23 is now a dead store.
Preserve the intent of the test by splitting it up into two functions.

Reduces code size a bit:

name        old object-bytes  new object-bytes  delta
Template           386k ± 0%         386k ± 0%    ~     (all equal)
Unicode            202k ± 0%         202k ± 0%    ~     (all equal)
GoTypes           1.16M ± 0%        1.16M ± 0%    ~     (all equal)
Compiler          3.92M ± 0%        3.91M ± 0%  -0.19%  (p=0.008 n=5+5)
SSA               7.91M ± 0%        7.91M ± 0%    ~     (all equal)
Flate              228k ± 0%         228k ± 0%  -0.05%  (p=0.008 n=5+5)
GoParser           283k ± 0%         283k ± 0%    ~     (all equal)
Reflect            952k ± 0%         952k ± 0%  -0.06%  (p=0.008 n=5+5)
Tar                188k ± 0%         188k ± 0%  -0.09%  (p=0.008 n=5+5)
XML                406k ± 0%         406k ± 0%  -0.02%  (p=0.008 n=5+5)
[Geo mean]         649k              648k       -0.04%

Fixes #18872

Change-Id: Ifeed0f71f13849732999aa731cc2bf40c0f0e32a
Reviewed-on: https://go-review.googlesource.com/43154
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/asm_test.go
src/cmd/compile/internal/gc/walk.go
test/writebarrier.go

index 1ab32f6e24481396d823b8fb4c3c2c83416eab4b..bac09ef295784eb5c2d9088fc2782c544cbe72b9 100644 (file)
@@ -364,7 +364,19 @@ var linuxAMD64Tests = []*asmTest{
                `,
                []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.
+       // SSA-able composite literal initialization. Issue 18872.
+       {
+               `
+               type T18872 struct {
+                       a, b, c, d int
+               }
+
+               func f18872(p *T18872) {
+                       *p = T18872{1, 2, 3, 4}
+               }
+               `,
+               []string{"\tMOVQ\t[$]1", "\tMOVQ\t[$]2", "\tMOVQ\t[$]3", "\tMOVQ\t[$]4"},
+       },
        // Also test struct containing pointers (this was special because of write barriers).
        {
                `
index 293e18eef09640a423a54a5c188e8062f4cd8d34..557293b9f01bcdf38969e5a12b3836f08f6db736 100644 (file)
@@ -1624,7 +1624,7 @@ opswitch:
                n = cmp
 
        case OARRAYLIT, OSLICELIT, OMAPLIT, OSTRUCTLIT, OPTRLIT:
-               if isStaticCompositeLiteral(n) {
+               if isStaticCompositeLiteral(n) && !canSSAType(n.Type) {
                        // n can be directly represented in the read-only data section.
                        // Make direct reference to the static data. See issue 12841.
                        vstat := staticname(n.Type)
index f3149e1b49628a5017fd48f5cd5558d0c1d02aac..55ba81e764e08cdb4dbbf859d55019090dbf4915 100644 (file)
@@ -238,11 +238,14 @@ var i23 int
 // f23x: zeroing global needs write barrier for the hybrid barrier.
 func f23a() {
        t23 = T23{} // ERROR "write barrier"
+}
+
+func f23b() {
        // also test partial assignments
        t23 = T23{a: 1} // ERROR "write barrier"
 }
 
-func f23b() {
+func f23c() {
        t23 = T23{} // no barrier (dead store)
        // also test partial assignments
        t23 = T23{p: &i23} // ERROR "write barrier"