aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2022-07-27 09:56:38 -0700
committerKeith Randall <khr@golang.org>2022-08-08 17:36:47 +0000
commitc2a9c55823b1ed14f84d8ce8880dbda3f5b01eb0 (patch)
tree5d235511ab25de69ede9114dc3144c47a7d505b0 /test/codegen
parentebf182c82de21858a1a167cc8d252ae85de806a7 (diff)
downloadgo-c2a9c55823b1ed14f84d8ce8880dbda3f5b01eb0.tar.xz
cmd/compile: optimize unsafe.Slice generated code
We don't need a multiply when the element type is size 0 or 1. The panic functions don't return, so we don't need any post-call code (register restores, etc.). Change-Id: I0dcea5df56d29d7be26554ddca966b3903c672e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/419754 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/slices.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/codegen/slices.go b/test/codegen/slices.go
index d20aa9eddf..99bdd50e52 100644
--- a/test/codegen/slices.go
+++ b/test/codegen/slices.go
@@ -6,6 +6,8 @@
package codegen
+import "unsafe"
+
// This file contains code generation tests related to the handling of
// slice types.
@@ -368,3 +370,16 @@ func SliceWithSubtractBound(a []int, b int) []int {
// ppc64:"SUBC",-"NEG"
return a[(3 - b):]
}
+
+// --------------------------------------- //
+// Code generation for unsafe.Slice //
+// --------------------------------------- //
+
+func Slice1(p *byte, i int) []byte {
+ // amd64:-"MULQ"
+ return unsafe.Slice(p, i)
+}
+func Slice0(p *struct{}, i int) []struct{} {
+ // amd64:-"MULQ"
+ return unsafe.Slice(p, i)
+}