1 Commits

Author SHA1 Message Date
dorbmon
38ac6577cb cmd/compile: forward small Load through Move to avoid redundant copies
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>
2026-03-10 20:06:05 -07:00