diff options
| author | Keith Randall <khr@golang.org> | 2022-10-27 08:28:06 -0700 |
|---|---|---|
| committer | Keith Randall <khr@google.com> | 2022-10-27 17:09:50 +0000 |
| commit | 0156b797e6f0d1a116a19cd852f569ec2c2eec11 (patch) | |
| tree | 045ca4dc0202cb6844ff25f5096c432e9f30fea7 /test | |
| parent | da0913f814dd4dcd28698dc5b85a3347b77b5550 (diff) | |
| download | go-0156b797e6f0d1a116a19cd852f569ec2c2eec11.tar.xz | |
cmd/compile: recognize when the result of append has a constant length
Fixes a performance regression due to CL 418554.
Fixes #56440
Change-Id: I6ff152e9b83084756363f49ee6b0844a7a284880
Reviewed-on: https://go-review.googlesource.com/c/go/+/445875
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/codegen/issue56440.go | 18 | ||||
| -rw-r--r-- | test/prove.go | 2 |
2 files changed, 19 insertions, 1 deletions
diff --git a/test/codegen/issue56440.go b/test/codegen/issue56440.go new file mode 100644 index 0000000000..36b52ace03 --- /dev/null +++ b/test/codegen/issue56440.go @@ -0,0 +1,18 @@ +// asmcheck + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Check to make sure that we recognize when the length of an append +// is constant. We check this by making sure that the constant length +// is folded into a load offset. + +package p + +func f(x []int) int { + s := make([]int, 3) + s = append(s, 4, 5) + // amd64:`MOVQ\t40\(.*\),` + return x[len(s)] +} diff --git a/test/prove.go b/test/prove.go index 1be257f206..7792b432f9 100644 --- a/test/prove.go +++ b/test/prove.go @@ -500,7 +500,7 @@ func f19() (e int64, err error) { last := len(stack) - 1 e = stack[last] // Buggy compiler prints "Disproved Leq64" for the next line. - stack = stack[:last] // ERROR "Proved IsSliceInBounds" + stack = stack[:last] return e, nil } |
