cmd/compile: optimize remaining convT2I calls
See #14874
Updates #6853
This change adds a compiler optimization for non pointer shaped convT2I.
Since itab symbols are now emitted by the compiler, the itab address can
be passed directly to convT2I instead of passing the iface type and a
cache pointer argument.
Compilebench results for the 5-commits series ending here:
name old time/op new time/op delta
Template 336ms ± 4% 344ms ± 4% +2.61% (p=0.027 n=9+8)
Unicode 165ms ± 6% 173ms ± 7% +5.11% (p=0.014 n=9+9)
GoTypes 1.09s ± 1% 1.06s ± 2% -3.29% (p=0.000 n=9+9)
Compiler 5.09s ±10% 4.75s ±10% -6.64% (p=0.011 n=10+10)
MakeBash 31.1s ± 5% 30.3s ± 3% ~ (p=0.089 n=10+10)
name old text-bytes new text-bytes delta
HelloSize 558k ± 0% 558k ± 0% +0.02% (p=0.000 n=10+10)
CmdGoSize 6.24M ± 0% 6.11M ± 0% -2.11% (p=0.000 n=10+10)
name old data-bytes new data-bytes delta
HelloSize 3.66k ± 0% 3.74k ± 0% +2.41% (p=0.000 n=10+10)
CmdGoSize 134k ± 0% 162k ± 0% +20.76% (p=0.000 n=10+10)
name old bss-bytes new bss-bytes delta
HelloSize 126k ± 0% 126k ± 0% ~ (all samples are equal)
CmdGoSize 149k ± 0% 146k ± 0% -2.17% (p=0.000 n=10+10)
name old exe-bytes new exe-bytes delta
HelloSize 924k ± 0% 924k ± 0% +0.05% (p=0.000 n=10+10)
CmdGoSize 9.77M ± 0% 9.62M ± 0% -1.47% (p=0.000 n=10+10)
Change-Id: Ib230ddc04988824035c32287ae544a965fedd344
Reviewed-on: https://go-review.googlesource.com/20902
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Michel Lespinasse <walken@google.com>
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 1511c87..7be30aa 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -1003,63 +1003,15 @@
}
var ll []*Node
- if !Isinter(n.Left.Type) {
- ll = append(ll, typename(n.Left.Type))
- }
- if !isnilinter(n.Type) {
- ll = append(ll, typename(n.Type))
- }
- if !Isinter(n.Left.Type) && !isnilinter(n.Type) {
- sym := Pkglookup(Tconv(n.Left.Type, FmtLeft)+"."+Tconv(n.Type, FmtLeft), itabpkg)
- if sym.Def == nil {
- l := Nod(ONAME, nil, nil)
- l.Sym = sym
- l.Type = Ptrto(Types[TUINT8])
- l.Addable = true
- l.Class = PEXTERN
- l.Xoffset = 0
- sym.Def = l
- ggloblsym(sym, int32(Widthptr), obj.DUPOK|obj.NOPTR)
+ if isnilinter(n.Type) {
+ if !Isinter(n.Left.Type) {
+ ll = append(ll, typename(n.Left.Type))
}
-
- l := Nod(OADDR, sym.Def, nil)
- l.Addable = true
- ll = append(ll, l)
-
- if isdirectiface(n.Left.Type) {
- // For pointer types, we can make a special form of optimization
- //
- // These statements are put onto the expression init list:
- // Itab *tab = atomicloadtype(&cache);
- // if(tab == nil)
- // tab = typ2Itab(type, itype, &cache);
- //
- // The CONVIFACE expression is replaced with this:
- // OEFACE{tab, ptr};
- l := temp(Ptrto(Types[TUINT8]))
-
- n1 := Nod(OAS, l, sym.Def)
- n1 = typecheck(n1, Etop)
- init.Append(n1)
-
- fn := syslook("typ2Itab")
- n1 = Nod(OCALL, fn, nil)
- n1.List.Set(ll)
- n1 = typecheck(n1, Erv)
- n1 = walkexpr(n1, init)
-
- n2 := Nod(OIF, nil, nil)
- n2.Left = Nod(OEQ, l, nodnil())
- n2.Nbody.Set1(Nod(OAS, l, n1))
- n2.Likely = -1
- n2 = typecheck(n2, Etop)
- init.Append(n2)
-
- l = Nod(OEFACE, l, n.Left)
- l.Typecheck = n.Typecheck
- l.Type = n.Type
- n = l
- break
+ } else {
+ if Isinter(n.Left.Type) {
+ ll = append(ll, typename(n.Type))
+ } else {
+ ll = append(ll, itabname(n.Left.Type, n.Type))
}
}