]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: eliminate copy for static literals
authorKeith Randall <khr@golang.org>
Mon, 18 Apr 2016 18:17:55 +0000 (11:17 -0700)
committerKeith Randall <khr@golang.org>
Mon, 18 Apr 2016 18:51:10 +0000 (18:51 +0000)
commitb024ed0d944c0f839e699fb10af633d295abb311
tree5f514f54da2ce029089157ca50370c6a329d007d
parentf60fcca5f1e7b7a33e219ec45d4bd9dc58dd2552
cmd/compile: eliminate copy for static literals

*p = [5]byte{1,2,3,4,5}

First we allocate a global containing the RHS.  Then we copy
that global to a local stack variable, and then copy that local
stack variable to *p.  The intermediate copy is unnecessary.

Note that this only works if the RHS is completely constant.
If the code was:
*p = [5]byte{1,2,x,4,5}
this optimization doesn't apply as we have to construct the
RHS on the stack before copying it to *p.

Fixes #12841

Change-Id: I7cd0404ecc7a2d1750cbd8fe1222dba0fa44611f
Reviewed-on: https://go-review.googlesource.com/22192
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/walk.go