diff options
author | Iskander Sharipov <iskander.sharipov@intel.com> | 2018-09-04 23:14:53 +0300 |
---|---|---|
committer | Iskander Sharipov <iskander.sharipov@intel.com> | 2018-09-17 11:14:58 +0000 |
commit | 859cf7fc0f4535ab3cdec15c81860f5fd2ae5b01 (patch) | |
tree | 0a00a3b061ea264bc206c8174529a608b888bb7f /test/escape2n.go | |
parent | 2d82465d18520820c52fea6b5e400a692ffdb92a (diff) | |
download | go-859cf7fc0f4535ab3cdec15c81860f5fd2ae5b01.tar.gz go-859cf7fc0f4535ab3cdec15c81860f5fd2ae5b01.zip |
cmd/compile/internal/gc: handle array slice self-assign in esc.go
Instead of skipping all OSLICEARR, skip only ones with non-pointer
array type. For pointers to arrays, it's safe to apply the
self-assignment slicing optimizations.
Refactored the matching code into separate function for readability.
This is an extension to already existing optimization.
On its own, it does not improve any code under std, but
it opens some new optimization opportunities. One
of them is described in the referenced issue.
Updates #7921
Change-Id: I08ac660d3ef80eb15fd7933fb73cf53ded9333ad
Reviewed-on: https://go-review.googlesource.com/133375
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/escape2n.go')
-rw-r--r-- | test/escape2n.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/test/escape2n.go b/test/escape2n.go index b1130d3c3c..4b1ca1eab8 100644 --- a/test/escape2n.go +++ b/test/escape2n.go @@ -1593,11 +1593,12 @@ func ptrlitEscape() { // self-assignments type Buffer struct { - arr [64]byte - buf1 []byte - buf2 []byte - str1 string - str2 string + arr [64]byte + arrPtr *[64]byte + buf1 []byte + buf2 []byte + str1 string + str2 string } func (b *Buffer) foo() { // ERROR "\(\*Buffer\).foo b does not escape$" @@ -1611,6 +1612,11 @@ func (b *Buffer) bar() { // ERROR "leaking param: b$" b.buf1 = b.arr[1:2] // ERROR "b.arr escapes to heap$" } +func (b *Buffer) arrayPtr() { // ERROR "\(\*Buffer\).arrayPtr b does not escape" + b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" + b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" +} + func (b *Buffer) baz() { // ERROR "\(\*Buffer\).baz b does not escape$" b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" |