[go] cmd/compile/internal/walk: expand makeslicecopy optimization

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Aug 14, 2026, 11:02:44 PM (2 days ago) Aug 14
to Oleg Aleksandrov, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Dmitri Shuralyov, Dmitri Shuralyov, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Arseny Samoylov, Matthew Dempsky, Martin Möhrmann, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
cmd/compile/internal/walk: expand makeslicecopy optimization

The make+copy optimization previously required both the source and
destination to be simple non-address-taken variables.

Relax this restriction to require only one side to be such a variable.
The other expression only needs to be independent of it, which is
sufficient to preserve the correctness of the transformation.

This allows more make+copy patterns to be lowered to
runtime.makeslicecopy.

The benchmarks results:
goos: linux
goarch: arm64
pkg: runtime
│ base.stat │ improved.stat │
│ sec/op │ sec/op vs base │
MakeSliceCopyComplexExpressions/Src/Byte/mallocmove-4 130.1n ± 2% 124.2n ± 2% -4.53% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Src/Byte/makecopy-4 134.2n ± 2% 126.6n ± 1% -5.66% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Src/Byte/nilappend-4 132.2n ± 2% 132.0n ± 1% ~ (p=0.617 n=10)
MakeSliceCopyComplexExpressions/Src/Int/mallocmove-4 130.6n ± 2% 124.0n ± 2% -5.09% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Src/Int/makecopy-4 131.3n ± 2% 126.7n ± 1% -3.50% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Src/Int/nilappend-4 130.8n ± 4% 130.8n ± 2% ~ (p=0.630 n=10)
MakeSliceCopyComplexExpressions/Src/Ptr/mallocmove-4 157.5n ± 1% 150.1n ± 1% -4.67% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Src/Ptr/makecopy-4 157.1n ± 1% 143.8n ± 1% -8.46% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Src/Ptr/nilappend-4 156.3n ± 1% 156.4n ± 1% ~ (p=0.643 n=10)
MakeSliceCopyComplexExpressions/Dst/Byte/mallocmove-4 132.4n ± 1% 124.6n ± 2% -5.82% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Dst/Byte/makecopy-4 134.7n ± 2% 126.4n ± 2% -6.13% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Dst/Byte/nilappend-4 131.8n ± 1% 130.8n ± 1% ~ (p=0.425 n=10)
MakeSliceCopyComplexExpressions/Dst/Int/mallocmove-4 130.8n ± 3% 122.3n ± 3% -6.42% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Dst/Int/makecopy-4 132.7n ± 2% 125.0n ± 1% -5.80% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Dst/Int/nilappend-4 132.7n ± 2% 130.9n ± 1% ~ (p=0.118 n=10)
MakeSliceCopyComplexExpressions/Dst/Ptr/mallocmove-4 154.8n ± 2% 150.4n ± 0% -2.91% (p=0.000 n=10)
MakeSliceCopyComplexExpressions/Dst/Ptr/makecopy-4 153.7n ± 2% 153.8n ± 2% ~ (p=0.897 n=10)
MakeSliceCopyComplexExpressions/Dst/Ptr/nilappend-4 157.2n ± 2% 156.1n ± 1% ~ (p=0.050 n=10)
geomean 139.6n 134.8n -3.47%
Change-Id: Ide36ece8a9bf9480e80dd22811b8e4de4946d335
Reviewed-by: Keith Randall <k...@golang.org>
Auto-Submit: Keith Randall <k...@golang.org>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Keith Randall <k...@google.com>
Files:
  • M src/cmd/compile/internal/walk/order.go
  • M src/runtime/slice_test.go
  • M test/codegen/slices.go
Change size: L
Delta: 3 files changed, 228 insertions(+), 22 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ide36ece8a9bf9480e80dd22811b8e4de4946d335
Gerrit-Change-Number: 806600
Gerrit-PatchSet: 3
Gerrit-Owner: Oleg Aleksandrov <aleksandr...@gmail.com>
Gerrit-Reviewer: Arseny Samoylov <samoylo...@gmail.com>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
Gerrit-Reviewer: Matthew Dempsky <mat...@go.dev>
Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages