aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2022-11-30 09:45:29 +0100
committerKeith Randall <khr@golang.org>2023-01-20 04:57:35 +0000
commitfc814056aae191f61f46bef5be6e29ee3dc09b89 (patch)
tree93c75e8fcf10a4e3d7c4b7116ea7b4bfd71a55e6 /test/codegen
parent57236fe9f72c7dae447f07899e9b5b3bcd06f2af (diff)
downloadgo-fc814056aae191f61f46bef5be6e29ee3dc09b89.tar.xz
cmd/compile: rewrite empty makeslice to zerobase pointer
make\(\[\][a-zA-Z0-9]+, 0\) is seen 52 times in the go source. And at least 391 times on internet: https://grep.app/search?q=make%5C%28%5C%5B%5C%5D%5Ba-zA-Z0-9%5D%2B%2C%200%5C%29&regexp=true This used to compile to calling runtime.makeslice. However we can copy what we do for []T{}, just use a zerobase pointer. On my machine this is 10x faster (from 3ns to 0.3ns). Note that an empty loop also runs in 0.3ns, so this really is free when you count superscallar execution. Change-Id: I1cfe7e69f5a7a4dabbc71912ce6a4f8a2d4a7f3c Reviewed-on: https://go-review.googlesource.com/c/go/+/454036 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Jakub Ciolek <jakub@ciolek.dev>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/slices.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/codegen/slices.go b/test/codegen/slices.go
index fa4142d767..f897200fb9 100644
--- a/test/codegen/slices.go
+++ b/test/codegen/slices.go
@@ -337,6 +337,12 @@ func SliceMakeCopyNoMemmoveDifferentLen(s []int) []int {
return a
}
+func SliceMakeEmptyPointerToZerobase() []int {
+ // amd64:`LEAQ.+runtime\.zerobase`
+ // amd64:-`.*runtime\.makeslice`
+ return make([]int, 0)
+}
+
// ---------------------- //
// Nil check of &s[0] //
// ---------------------- //