]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: common up code in fuse for joining blocks
authorDavid Chase <drchase@google.com>
Fri, 18 May 2018 21:43:11 +0000 (17:43 -0400)
committerDavid Chase <drchase@google.com>
Tue, 22 May 2018 21:46:36 +0000 (21:46 +0000)
There's semantically-but-not-literally equivalent code in
two cases for joining blocks' value lists in ssa/fuse.go.
It can be made literally equivalent, then commoned up.

Updates #25426.

Change-Id: Id1819366c9d22e5126f9203dcd4c622423994110
Reviewed-on: https://go-review.googlesource.com/113719
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/ssa/fuse.go

index ca840e37ff4b1ab3ecd5f71fbcc5596eee1bc9d8..4f9a2ad9cab78e71e61bed0925e418b05208d393 100644 (file)
@@ -155,21 +155,21 @@ func fuseBlockPlain(b *Block) bool {
        // debugging information depends on the order of *Values in Blocks.
        // This can also cause changes in the order (which may affect other
        // optimizations and possibly compiler output) for 32-vs-64 bit compilation
-       // platforms (word size affects allocation bucket size affects slice size).
+       // platforms (word size affects allocation bucket size affects slice capacity).
        if cap(c.Values) >= cap(b.Values) || len(b.Values) <= len(b.valstorage) {
                bl := len(b.Values)
                cl := len(c.Values)
+               var t []*Value // construct t = b.Values followed-by c.Values, but with attention to allocation.
                if cap(c.Values) < bl+cl {
                        // reallocate
-                       t := make([]*Value, 0, bl+cl)
-                       t = append(t, b.Values...)
-                       c.Values = append(t, c.Values...)
+                       t = make([]*Value, bl+cl)
                } else {
                        // in place.
-                       c.Values = c.Values[0 : bl+cl]
-                       copy(c.Values[bl:], c.Values)
-                       copy(c.Values, b.Values)
+                       t = c.Values[0 : bl+cl]
                }
+               copy(t[bl:], c.Values) // possibly in-place
+               c.Values = t
+               copy(c.Values, b.Values)
        } else {
                c.Values = append(b.Values, c.Values...)
        }