mirror of
https://github.com/golang/go.git
synced 2026-04-01 17:07:17 +09:00
Fixes #77720 Add a generic SSA rewrite that forwards `Load` from a `Move` destination back to the `Move` source when it is provably safe, so field reads like `s.h.Value().typ` don’t force a full struct copy. - Add `Load <- Move` rewrite in `generic.rules` with safety guard: non-volatile source - Tweak `fixedbugs/issue22200*` so that it can still trigger the "stack frame too large" error. - Regenerate `rewritegeneric.go`. - Add `test/codegen/moveload.go` to assert no `MOVUPS` and direct `MOVBLZX` in both direct and inlined forms. Benchmark results (linux/amd64, i7-14700KF): $ go test cmd/compile/internal/test -run='^$' -bench='MoveLoad' -count=20 Before: BenchmarkMoveLoadTypViaValue-20 ~76.9 ns/op BenchmarkMoveLoadTypViaPtr-20 ~1.97 ns/op After: BenchmarkMoveLoadTypViaValue-20 ~1.894 ns/op BenchmarkMoveLoadTypViaPtr-20 ~1.905 ns/op The rewrite removes the redundant struct copy in `s.h.Value().typ`, bringing it in line with the direct pointer form. Change-Id: Iddf2263e390030ba013e0642a695b87c75f899da Reviewed-on: https://go-review.googlesource.com/c/go/+/748200 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Mark Freeman <markfreeman@google.com>
39 lines
783 B
Go
39 lines
783 B
Go
// asmcheck
|
|
|
|
// Copyright 2026 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.
|
|
|
|
package codegen
|
|
|
|
// From issue #77720: cmd/compile: field access on struct-returning method copies entire struct
|
|
|
|
type moveLoadBig struct {
|
|
typ int8
|
|
index int64
|
|
str string
|
|
pkgID string
|
|
}
|
|
|
|
type moveLoadHandle[T any] struct {
|
|
value *T
|
|
}
|
|
|
|
func (h moveLoadHandle[T]) Value() T { return *h.value }
|
|
|
|
type moveLoadS struct {
|
|
h moveLoadHandle[moveLoadBig]
|
|
}
|
|
|
|
func moveLoadFieldViaValue(s moveLoadS) int8 {
|
|
// amd64:-`MOVUPS`
|
|
// amd64:`MOVBLZX`
|
|
return s.h.Value().typ
|
|
}
|
|
|
|
func moveLoadFieldViaValueInline(ss []moveLoadS, i int) int8 {
|
|
// amd64:-`MOVUPS`
|
|
// amd64:`MOVBLZX`
|
|
return ss[i&7].h.Value().typ
|
|
}
|