From d0964e172b83db45d167b21e93b79fe86b158760 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 15 Jun 2023 09:14:12 -0700 Subject: 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 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Run-TryBot: Keith Randall --- test/codegen/strings.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/codegen') 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 -- cgit v1.3-5-g9baa