aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorAlexander Musman <alexander.musman@gmail.com>2025-07-05 23:16:36 +0300
committerGopher Robot <gobot@golang.org>2025-11-26 09:58:51 -0800
commitdda7c8253dd5e4dc5732187f1c039325bca53c8c (patch)
tree7ad50fc4241295887289c38e1f2299b5df320689 /test/codegen
parent4976606a2f9203f4520c28d775e67fc32f5853ed (diff)
downloadgo-dda7c8253dd5e4dc5732187f1c039325bca53c8c.tar.xz
cmd/compile,internal/bytealg: add MemEq intrinsic for runtime.memequal
Introduce a new MemEq SSA operation for runtime.memequal. The operation is initially implemented for arm64. The change adds opt rules (following existing rules for call to runtime.memequal), working with MemEq, and a later op version LoweredMemEq which may be lowered differently for more constant size cases in future (for other targets as well as for arm64). The new MemEq SSA operation does not have memory result, allowing cse of loads operations around it. Code size difference (for arm64 linux): Executable Old .text New .text Change ------------------------------------------------------- asm 1970420 1969668 -0.04% cgo 1741220 1740212 -0.06% compile 8956756 8959428 +0.03% cover 1879332 1878772 -0.03% link 2574116 2572660 -0.06% preprofile 867124 866820 -0.04% vet 2890404 2888596 -0.06% Change-Id: I6ab507929b861884d17d5818cfbd152cf7879751 Reviewed-on: https://go-review.googlesource.com/c/go/+/686655 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/comparisons.go11
-rw-r--r--test/codegen/memcse.go17
2 files changed, 28 insertions, 0 deletions
diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go
index 74a7d689da..bcce21e404 100644
--- a/test/codegen/comparisons.go
+++ b/test/codegen/comparisons.go
@@ -660,6 +660,17 @@ func equalVarString8(a string) bool {
return a[:8] == b
}
+func equalVarStringNoSpill(a,b string) bool {
+ s := string("ZZZZZZZZZ")
+ // arm64:".*memequal"
+ memeq1 := a[:9] == s
+ // arm64:-".*"
+ memeq2 := s == a[:9]
+ // arm64:-"MOVB\tR0,.*SP",".*memequal"
+ memeq3 := s == b[:9]
+ return memeq1 && memeq2 && memeq3
+}
+
func cmpToCmn(a, b, c, d int) int {
var c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11 int
// arm64:`CMN`,-`CMP`
diff --git a/test/codegen/memcse.go b/test/codegen/memcse.go
new file mode 100644
index 0000000000..d2eb156168
--- /dev/null
+++ b/test/codegen/memcse.go
@@ -0,0 +1,17 @@
+// asmcheck
+
+// Copyright 2025 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.
+
+// Test common subexpression elimination of loads around other operations.
+
+package codegen
+
+func loadsAroundMemEqual(p *int, s1, s2 string) (int, bool) {
+ x := *p
+ eq := s1 == s2
+ y := *p
+ // arm64:"MOVD ZR, R0"
+ return x - y, eq
+}