]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize convT2I as a two-word copy when T is pointer-shaped
authorMichel Lespinasse <walken@google.com>
Fri, 18 Mar 2016 23:20:20 +0000 (16:20 -0700)
committerMichel Lespinasse <walken@google.com>
Tue, 29 Mar 2016 02:21:41 +0000 (02:21 +0000)
See #14874

This change adds a compiler optimization for pointer shaped convT2I.
Since itab symbols are now emitted by the compiler, the itab address can
be directly moved into the iface structure.

Change-Id: I311483af544519ca682c5f872960717ead772f26
Reviewed-on: https://go-review.googlesource.com/20901
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/walk.go

index ecf98b93880f2cdd34a08a3080183629bce1c23c..54673b1ea55c152de56a6f9bf9f044c1dba0eb5e 100644 (file)
@@ -947,7 +947,7 @@ func typename(t *Type) *Node {
        return n
 }
 
-func itabnamesym(t, itype *Type) *Sym {
+func itabname(t, itype *Type) *Node {
        if t == nil || (Isptr[t.Etype] && t.Type == nil) || isideal(t) {
                Fatalf("itabname %v", t)
        }
@@ -961,7 +961,13 @@ func itabnamesym(t, itype *Type) *Sym {
 
                itabs = append(itabs, itabEntry{t: t, itype: itype, sym: s})
        }
-       return s.Def.Sym
+
+       n := Nod(OADDR, s.Def, nil)
+       n.Type = Ptrto(s.Def.Type)
+       n.Addable = true
+       n.Ullman = 2
+       n.Typecheck = 1
+       return n
 }
 
 // isreflexive reports whether t has a reflexive equality operator.
index 90ed401a43f097e927abfc8358b451e10bd509d8..1511c878b11d469e613f01cc2ed248c65a5b08f9 100644 (file)
@@ -987,19 +987,21 @@ opswitch:
        case OCONVIFACE:
                n.Left = walkexpr(n.Left, init)
 
-               // Optimize convT2E as a two-word copy when T is pointer-shaped.
-               if isnilinter(n.Type) && isdirectiface(n.Left.Type) {
-                       l := Nod(OEFACE, typename(n.Left.Type), n.Left)
+               // Optimize convT2E or convT2I as a two-word copy when T is pointer-shaped.
+               if isdirectiface(n.Left.Type) {
+                       var t *Node
+                       if isnilinter(n.Type) {
+                               t = typename(n.Left.Type)
+                       } else {
+                               t = itabname(n.Left.Type, n.Type)
+                       }
+                       l := Nod(OEFACE, t, n.Left)
                        l.Type = n.Type
                        l.Typecheck = n.Typecheck
                        n = l
                        break
                }
 
-               if isdirectiface(n.Left.Type) {
-                       itabnamesym(n.Left.Type, n.Type)
-               }
-
                var ll []*Node
                if !Isinter(n.Left.Type) {
                        ll = append(ll, typename(n.Left.Type))