]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: generalize isfat to handle 1-field structs and 1-element arrays
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 4 Sep 2019 04:11:22 +0000 (11:11 +0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 12 Sep 2019 06:48:02 +0000 (06:48 +0000)
After CL 192979, it is safe now to optimize isfat slightly to handle
1-field structs and 1-element arrays.

Change-Id: Ie3bc30299abbcef36eee7a0681997cc2f88ed6a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/192980
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

index 7d3377f40c14786e05695709f7a61130fee2bf77..6abbfe757eb5b4892845c5f29e4335c5cb8e471c 100644 (file)
@@ -304,7 +304,7 @@ func (lv *Liveness) valueEffects(v *ssa.Value) (int32, liveEffect) {
        var effect liveEffect
        // Read is a read, obviously.
        //
-       // Addr is a read also, as any subseqent holder of the pointer must be able
+       // Addr is a read also, as any subsequent holder of the pointer must be able
        // to see all the values (including initialization) written so far.
        // This also prevents a variable from "coming back from the dead" and presenting
        // stale pointers to the garbage collector. See issue 28445.
@@ -1450,12 +1450,25 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
        return lv.livenessMap
 }
 
+// TODO(cuonglm,mdempsky): Revisit after #24416 is fixed.
 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
                }
        }