aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorYoulin Feng <fengyoulin@live.com>2025-09-11 23:57:38 +0800
committerGopher Robot <gobot@golang.org>2025-11-04 12:46:15 -0800
commitc7ccbddf22884f54885fd23143d1b2087ab6e53c (patch)
treee6c35024eacd6f8fac92316d87c3c333bdef8bb0 /test/codegen
parent75b2bb1d1a62e69763aea6761b5be4b9c69e0214 (diff)
downloadgo-c7ccbddf22884f54885fd23143d1b2087ab6e53c.tar.xz
cmd/compile/internal/ssa: more aggressive on dead auto elim
Propagate "unread" across OpMoves. If the addr of this auto is only used by an OpMove as its source arg, and the OpMove's target arg is the addr of another auto. If the 2nd auto can be eliminated, this one can also be eliminated. This CL eliminates unnecessary memory copies and makes the frame smaller in the following code snippet: func contains(m map[string][16]int, k string) bool { _, ok := m[k] return ok } These are the benchmark results followed by the benchmark code: goos: linux goarch: amd64 cpu: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Map1Access2Ok-8 9.582n ± 2% 9.226n ± 0% -3.72% (p=0.000 n=20) Map2Access2Ok-8 13.79n ± 1% 10.24n ± 1% -25.77% (p=0.000 n=20) Map3Access2Ok-8 68.68n ± 1% 12.65n ± 1% -81.58% (p=0.000 n=20) package main_test import "testing" var ( m1 = map[int]int{} m2 = map[int][16]int{} m3 = map[int][256]int{} ) func init() { for i := range 1000 { m1[i] = i m2[i] = [16]int{15:i} m3[i] = [256]int{255:i} } } func BenchmarkMap1Access2Ok(b *testing.B) { for i := range b.N { _, ok := m1[i%1000] if !ok { b.Errorf("%d not found", i) } } } func BenchmarkMap2Access2Ok(b *testing.B) { for i := range b.N { _, ok := m2[i%1000] if !ok { b.Errorf("%d not found", i) } } } func BenchmarkMap3Access2Ok(b *testing.B) { for i := range b.N { _, ok := m3[i%1000] if !ok { b.Errorf("%d not found", i) } } } Fixes #75398 Change-Id: If75e9caaa50d460efc31a94565b9ba28c8158771 Reviewed-on: https://go-review.googlesource.com/c/go/+/702875 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/maps.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/codegen/maps.go b/test/codegen/maps.go
index fe38c99cb8..48438eb90c 100644
--- a/test/codegen/maps.go
+++ b/test/codegen/maps.go
@@ -37,6 +37,28 @@ func AccessString2(m map[string]int) bool {
return ok
}
+func AccessStringIntArray2(m map[string][16]int, k string) bool {
+ // amd64:-"MOVUPS"
+ _, ok := m[k]
+ return ok
+}
+
+type Struct struct {
+ A, B, C, D, E, F, G, H, I, J int
+}
+
+func AccessStringStruct2(m map[string]Struct, k string) bool {
+ // amd64:-"MOVUPS"
+ _, ok := m[k]
+ return ok
+}
+
+func AccessIntArrayLarge2(m map[int][512]int, k int) bool {
+ // amd64:-"REP",-"MOVSQ"
+ _, ok := m[k]
+ return ok
+}
+
// ------------------- //
// String Conversion //
// ------------------- //