diff options
| author | Keith Randall <khr@golang.org> | 2025-11-20 09:42:16 -0800 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2025-11-26 13:33:51 -0800 |
| commit | 3c6bf6fbf38062b24a7cf0390f1e617d733851b3 (patch) | |
| tree | f7633e2d43d13d9976b6642b2f2a2d44e39f6e14 /test/codegen | |
| parent | efe9ad501d94743d87e500a7ba0b1732a89e9afd (diff) | |
| download | go-3c6bf6fbf38062b24a7cf0390f1e617d733851b3.tar.xz | |
cmd/compile: handle loops better during stack allocation of slices
Don't use the move2heap optimization if the move2heap is inside
a loop deeper than the declaration of the slice. We really only want
to do the move2heap operation once.
Change-Id: I4a68d01609c2c9d4e0abe4580839e70059393a81
Reviewed-on: https://go-review.googlesource.com/c/go/+/722440
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/append.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/codegen/append.go b/test/codegen/append.go index 0e58a48c45..e90fa87ed2 100644 --- a/test/codegen/append.go +++ b/test/codegen/append.go @@ -185,6 +185,38 @@ func Append17(n int) []int { return r } +func Append18(n int, p *[]int) { + var r []int + for i := range n { + // amd64:-`.*moveSliceNoCapNoScan` + *p = r + // amd64:`.*growslice` + r = append(r, i) + } +} + +func Append19(n int, p [][]int) { + for j := range p { + var r []int + for i := range n { + // amd64:`.*growslice` + r = append(r, i) + } + // amd64:`.*moveSliceNoCapNoScan` + p[j] = r + } +} + +func Append20(n int, p [][]int) { + for j := range p { + var r []int + // amd64:`.*growslice` + r = append(r, 0) + // amd64:-`.*moveSliceNoCapNoScan` + p[j] = r + } +} + //go:noinline func useSlice(s []int) { } |
