aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/strings.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2023-06-15 09:14:12 -0700
committerKeith Randall <khr@golang.org>2023-07-26 17:17:28 +0000
commitd0964e172b83db45d167b21e93b79fe86b158760 (patch)
tree7f97e068236098c97672d22c2aa37acb9da66a2b /test/codegen/strings.go
parentf0894a00f4b756d4b9b4078af2e686b359493583 (diff)
downloadgo-d0964e172b83db45d167b21e93b79fe86b158760.tar.xz
cmd/compile: optimize s==s for strings
s==s is always true for strings. This comes up in NaN testing in generic code, where we want x==x to compile completely away except for float types. Fixes #60777 Change-Id: I3ce054b5121354de2f9751b010fb409f148cb637 Reviewed-on: https://go-review.googlesource.com/c/go/+/503795 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen/strings.go')
-rw-r--r--test/codegen/strings.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/codegen/strings.go b/test/codegen/strings.go
index 94512f5cd3..f98c062d1b 100644
--- a/test/codegen/strings.go
+++ b/test/codegen/strings.go
@@ -67,4 +67,14 @@ func ConstantLoad() {
bsink = []byte("0123456789ab")
}
+// self-equality is always true. See issue 60777.
+func EqualSelf(s string) bool {
+ // amd64:`MOVL\t\$1, AX`,-`.*memequal.*`
+ return s == s
+}
+func NotEqualSelf(s string) bool {
+ // amd64:`XORL\tAX, AX`,-`.*memequal.*`
+ return s != s
+}
+
var bsink []byte