From 3f0437e175d66a9c3d9ff1b201c4bb1b504dbfa7 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 4 Sep 2019 11:11:22 +0700 Subject: [PATCH] cmd/compile: generalize isfat to handle 1-field structs and 1-element arrays 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/plive.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go index 7d3377f40c..6abbfe757e 100644 --- a/src/cmd/compile/internal/gc/plive.go +++ b/src/cmd/compile/internal/gc/plive.go @@ -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 } }