diff options
author | Keith Randall <khr@golang.org> | 2023-09-25 18:00:10 -0700 |
---|---|---|
committer | Keith Randall <khr@google.com> | 2023-10-09 18:39:50 +0000 |
commit | e0948d825d8dab1a685bcb94bfc9ad69b9b6c075 (patch) | |
tree | b302e30dbdf4f589c79ce3f8186f290e803eaaf6 /test | |
parent | 778880b00888066212864f95877c0febbebf7e69 (diff) | |
download | go-e0948d825d8dab1a685bcb94bfc9ad69b9b6c075.tar.gz go-e0948d825d8dab1a685bcb94bfc9ad69b9b6c075.zip |
cmd/compile: use type hash from itab field instead of type field
It is one less dependent load away, and right next to another
field in the itab we also load as part of the type switch or
type assert.
Change-Id: If7aaa7814c47bd79a6c7ed4232ece0bc1d63550e
Reviewed-on: https://go-review.googlesource.com/c/go/+/533117
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/codegen/switch.go | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/test/codegen/switch.go b/test/codegen/switch.go index 4103bf5297..980ea70561 100644 --- a/test/codegen/switch.go +++ b/test/codegen/switch.go @@ -129,11 +129,27 @@ type IJ interface { I J } +type K interface { + baz() +} // use a runtime call for type switches to interface types. func interfaceSwitch(x any) int { - // amd64:`CALL\truntime.interfaceSwitch`,`MOVL\t16\(.*\)`,`MOVQ\t8\(.*\)(.*\*8)` - // arm64:`CALL\truntime.interfaceSwitch`,`LDAR`,`MOVWU`,`MOVD\t\(R.*\)\(R.*\)` + // amd64:`CALL\truntime.interfaceSwitch`,`MOVL\t16\(AX\)`,`MOVQ\t8\(.*\)(.*\*8)` + // arm64:`CALL\truntime.interfaceSwitch`,`LDAR`,`MOVWU\t16\(R0\)`,`MOVD\t\(R.*\)\(R.*\)` + switch x.(type) { + case I: + return 1 + case J: + return 2 + default: + return 3 + } +} + +func interfaceSwitch2(x K) int { + // amd64:`CALL\truntime.interfaceSwitch`,`MOVL\t16\(AX\)`,`MOVQ\t8\(.*\)(.*\*8)` + // arm64:`CALL\truntime.interfaceSwitch`,`LDAR`,`MOVWU\t16\(R0\)`,`MOVD\t\(R.*\)\(R.*\)` switch x.(type) { case I: return 1 @@ -145,8 +161,17 @@ func interfaceSwitch(x any) int { } func interfaceCast(x any) int { - // amd64:`CALL\truntime.typeAssert`,`MOVL\t16\(.*\)`,`MOVQ\t8\(.*\)(.*\*1)` - // arm64:`CALL\truntime.typeAssert`,`LDAR`,`MOVWU`,`MOVD\t\(R.*\)\(R.*\)` + // amd64:`CALL\truntime.typeAssert`,`MOVL\t16\(AX\)`,`MOVQ\t8\(.*\)(.*\*1)` + // arm64:`CALL\truntime.typeAssert`,`LDAR`,`MOVWU\t16\(R0\)`,`MOVD\t\(R.*\)\(R.*\)` + if _, ok := x.(I); ok { + return 3 + } + return 5 +} + +func interfaceCast2(x K) int { + // amd64:`CALL\truntime.typeAssert`,`MOVL\t16\(AX\)`,`MOVQ\t8\(.*\)(.*\*1)` + // arm64:`CALL\truntime.typeAssert`,`LDAR`,`MOVWU\t16\(R0\)`,`MOVD\t\(R.*\)\(R.*\)` if _, ok := x.(I); ok { return 3 } @@ -154,7 +179,7 @@ func interfaceCast(x any) int { } func interfaceConv(x IJ) I { - // amd64:`CALL\truntime.typeAssert`,`MOVL\t16\(.*\)`,`MOVQ\t8\(.*\)(.*\*1)` - // arm64:`CALL\truntime.typeAssert`,`LDAR`,`MOVWU`,`MOVD\t\(R.*\)\(R.*\)` + // amd64:`CALL\truntime.typeAssert`,`MOVL\t16\(AX\)`,`MOVQ\t8\(.*\)(.*\*1)` + // arm64:`CALL\truntime.typeAssert`,`LDAR`,`MOVWU\t16\(R0\)`,`MOVD\t\(R.*\)\(R.*\)` return x } |