aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
authorJake Bailey <jacob.b.bailey@gmail.com>2025-09-05 13:36:47 -0700
committerGopher Robot <gobot@golang.org>2025-09-08 13:34:06 -0700
commit5b218461f98b354ac9bde4fdd4f7046fdf2d2029 (patch)
tree9068dc49b4388206691bae6b116bc7bed6637bcb /src/cmd/compile
parentb915e14490e1c3ac5a84c274bfab647e1cb105a7 (diff)
downloadgo-5b218461f98b354ac9bde4fdd4f7046fdf2d2029.tar.xz
cmd/compile: optimize loads from abi.Type.{Size_,PtrBytes,Kind_}
With the previous CL in place, we can now pretty easily optimize a few more loads from abi.Type. I've done Size_, PtrBytes, and Kind_, which are easily calculated. Among std/cmd, this rule fires a number of times: 75 abi.Type field Kind_ 50 abi.PtrType field Elem 14 abi.Type field Hash 4 abi.Type field Size_ 2 abi.Type field PtrBytes The other ones that show up when compiling std/cmd are TFlag and GCData, but these are not trivially calculated. Doing TFlag would probably be a decent help given it's often used in things like switches where statically knowing the kind could eliminate a bunch of dead code. Change-Id: Ic7fd2113fa7479af914d06916edbca60cc71819f Reviewed-on: https://go-review.googlesource.com/c/go/+/701298 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/reflectdata/reflect.go7
-rw-r--r--src/cmd/compile/internal/ssa/rewrite.go19
2 files changed, 23 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go
index c561d527a7..2849d4ee40 100644
--- a/src/cmd/compile/internal/reflectdata/reflect.go
+++ b/src/cmd/compile/internal/reflectdata/reflect.go
@@ -414,6 +414,10 @@ var kinds = []abi.Kind{
types.TUNSAFEPTR: abi.UnsafePointer,
}
+func ABIKindOfType(t *types.Type) abi.Kind {
+ return kinds[t.Kind()]
+}
+
var (
memhashvarlen *obj.LSym
memequalvarlen *obj.LSym
@@ -512,8 +516,7 @@ func dcommontype(c rttype.Cursor, t *types.Type) {
c.Field("Align_").WriteUint8(uint8(t.Alignment()))
c.Field("FieldAlign_").WriteUint8(uint8(t.Alignment()))
- kind := kinds[t.Kind()]
- c.Field("Kind_").WriteUint8(uint8(kind))
+ c.Field("Kind_").WriteUint8(uint8(ABIKindOfType(t)))
c.Field("Equal").WritePtr(eqfunc)
c.Field("GCData").WritePtr(gcsym)
diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go
index bc66c91a35..576f25a497 100644
--- a/src/cmd/compile/internal/ssa/rewrite.go
+++ b/src/cmd/compile/internal/ssa/rewrite.go
@@ -2005,7 +2005,7 @@ func isFixedLoad(v *Value, sym Sym, off int64) bool {
for _, f := range rttype.Type.Fields() {
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
switch f.Sym.Name {
- case "Hash":
+ case "Size_", "PtrBytes", "Hash", "Kind_":
return true
default:
// fmt.Println("unknown field", f.Sym.Name)
@@ -2061,13 +2061,30 @@ func rewriteFixedLoad(v *Value, sym Sym, sb *Value, off int64) *Value {
t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
+ ptrSizedOpConst := OpConst64
+ if f.Config.PtrSize == 4 {
+ ptrSizedOpConst = OpConst32
+ }
+
for _, f := range rttype.Type.Fields() {
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
switch f.Sym.Name {
+ case "Size_":
+ v.reset(ptrSizedOpConst)
+ v.AuxInt = int64(t.Size())
+ return v
+ case "PtrBytes":
+ v.reset(ptrSizedOpConst)
+ v.AuxInt = int64(types.PtrDataSize(t))
+ return v
case "Hash":
v.reset(OpConst32)
v.AuxInt = int64(types.TypeHash(t))
return v
+ case "Kind_":
+ v.reset(OpConst8)
+ v.AuxInt = int64(reflectdata.ABIKindOfType(t))
+ return v
default:
base.Fatalf("unknown field %s for fixedLoad of %s at offset %d", f.Sym.Name, lsym.Name, off)
}