aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2023-09-01 20:32:07 -0700
committerKeith Randall <khr@golang.org>2023-10-06 15:42:30 +0000
commit28f4ea16a240af6c5a417e20be77745329f817f1 (patch)
treea298be53ac70ba58b561a023c8ec41d2e16e8dfc /test/codegen
parent10da3b64af1aebfd146fa3b7ecf765ee1b0f0d7d (diff)
downloadgo-28f4ea16a240af6c5a417e20be77745329f817f1.tar.xz
cmd/compile: improve interface type switches
For type switches where the targets are interface types, call into the runtime once instead of doing a sequence of assert* calls. name old time/op new time/op delta SwitchInterfaceTypePredictable-24 26.6ns ± 1% 25.8ns ± 2% -2.86% (p=0.000 n=10+10) SwitchInterfaceTypeUnpredictable-24 39.3ns ± 1% 37.5ns ± 2% -4.57% (p=0.000 n=10+10) Not super helpful by itself, but this code organization allows followon CLs that add caching to the lookups. Change-Id: I7967f85a99171faa6c2550690e311bea8b54b01c Reviewed-on: https://go-review.googlesource.com/c/go/+/526657 Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/switch.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/codegen/switch.go b/test/codegen/switch.go
index 556d02a162..63b0dce8a6 100644
--- a/test/codegen/switch.go
+++ b/test/codegen/switch.go
@@ -118,3 +118,24 @@ func typeSwitch(x any) int {
}
return 7
}
+
+type I interface {
+ foo()
+}
+type J interface {
+ bar()
+}
+
+// use a runtime call for type switches to interface types.
+func interfaceSwitch(x any) int {
+ // amd64:`CALL\truntime.interfaceSwitch`
+ // arm64:`CALL\truntime.interfaceSwitch`
+ switch x.(type) {
+ case I:
+ return 1
+ case J:
+ return 2
+ default:
+ return 3
+ }
+}