]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: make isfat handle 1-element array, 1-field struct
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Thu, 30 May 2019 06:01:03 +0000 (13:01 +0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 28 Aug 2019 19:48:31 +0000 (19:48 +0000)
This will improve liveness analysis slightly, the same logic as
isdirectiface curently does. In:

type T struct {
    m map[int]int
}

        v := T{}
        v.m = make(map[int]int)

T is considered "fat", now it is not. So assigning to v.m is considered
to clobber the entire v.

This is follow up of CL 179057.

Change-Id: Id6b4807b8e8521ef5d8bcb14fedb6dceb9dbf18c
Reviewed-on: https://go-review.googlesource.com/c/go/+/179578
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/plive.go
test/live.go
test/live2.go

index 7d3377f40c14786e05695709f7a61130fee2bf77..591e2d14e2a7647114988af2a8b5ba3a812a490f 100644 (file)
@@ -1453,9 +1453,21 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
 func isfat(t *types.Type) bool {
        if t != nil {
                switch t.Etype {
-               case TSTRUCT, TARRAY, TSLICE, TSTRING,
+               case TSLICE, TSTRING,
                        TINTER: // maybe remove later
                        return true
+               case TARRAY:
+                       // Array of 1 element, check if element is fat
+                       if t.NumElem() == 1 {
+                               return isfat(t.Elem())
+                       }
+                       return true
+               case TSTRUCT:
+                       // Struct with 1 field, check if field is fat
+                       if t.NumFields() == 1 {
+                               return isfat(t.Field(0).Type)
+                       }
+                       return true
                }
        }
 
index ec51193725d100679b4b0324db62310d339e33eb..2c8972ef4f105c574c50c1b462e35fb3109cd49a 100644 (file)
@@ -659,7 +659,7 @@ func bad40() {
 
 func good40() {
        ret := T40{}              // ERROR "stack object ret T40$"
-       ret.m = make(map[int]int) // ERROR "live at call to fastrand: .autotmp_[0-9]+ ret$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
+       ret.m = make(map[int]int) // ERROR "live at call to fastrand: .autotmp_[0-9]+$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
        t := &ret
        printnl() // ERROR "live at call to printnl: ret$"
        // Note: ret is live at the printnl because the compiler moves &ret
index cea312f075187f2457bf5f36e4f0d9fb54aa8367..83a6cb7db60759dddff85f8ce4ba9542c19f0981 100644 (file)
@@ -27,14 +27,14 @@ func newT40() *T40 {
 }
 
 func bad40() {
-       t := newT40() // ERROR "live at call to makemap: ret$" "stack object ret T40$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
+       t := newT40() // ERROR "stack object ret T40$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
        printnl()     // ERROR "live at call to printnl: ret$"
        useT40(t)
 }
 
 func good40() {
        ret := T40{}                  // ERROR "stack object ret T40$"
-       ret.m = make(map[int]int, 42) // ERROR "live at call to makemap: ret$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
+       ret.m = make(map[int]int, 42) // ERROR "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
        t := &ret
        printnl() // ERROR "live at call to printnl: ret$"
        useT40(t)