diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-01-16 19:35:39 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-01-17 05:08:11 +0000 |
commit | 7ce2a8383d154ca1860286a9b5c8a1e6cf151a90 (patch) | |
tree | 2beadbe415f225280d29b9828349b8d70fad0dde /src/cmd/compile/internal/walk/complit.go | |
parent | ba0e8a92fa74768feaccb8c3e4e5791b2dbc382f (diff) | |
download | go-7ce2a8383d154ca1860286a9b5c8a1e6cf151a90.tar.gz go-7ce2a8383d154ca1860286a9b5c8a1e6cf151a90.zip |
[dev.regabi] cmd/compile: simplify stack temp initialization
This CL simplifies the previous one a little bit further, by combining
reordering stack-temporary initialization and getting rid of an
unneeded temporary variable. (Does not pass toolstash -cmp.)
Change-Id: I17799dfe368484f33a8ddd0ab4f68647d6262147
Reviewed-on: https://go-review.googlesource.com/c/go/+/284225
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/walk/complit.go')
-rw-r--r-- | src/cmd/compile/internal/walk/complit.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go index a7db453550..97e820238b 100644 --- a/src/cmd/compile/internal/walk/complit.go +++ b/src/cmd/compile/internal/walk/complit.go @@ -344,21 +344,18 @@ func slicelit(ctxt initContext, n *ir.CompLitExpr, var_ ir.Node, init *ir.Nodes) if !types.Identical(t, x.Type()) { panic("dotdotdot base type does not match order's assigned type") } - a = initStackTemp(init, x, vstat != nil) + a = initStackTemp(init, x, vstat) } else if n.Esc() == ir.EscNone { - if vstat == nil { - // TODO(mdempsky): Remove this useless temporary. - // It's only needed to keep toolstash happy. - typecheck.Temp(t) - } - a = initStackTemp(init, typecheck.Temp(t), vstat != nil) + a = initStackTemp(init, typecheck.Temp(t), vstat) } else { a = ir.NewUnaryExpr(base.Pos, ir.ONEW, ir.TypeNode(t)) } appendWalkStmt(init, ir.NewAssignStmt(base.Pos, vauto, a)) - if vstat != nil { - // copy static to heap (4) + if vstat != nil && n.Prealloc == nil && n.Esc() != ir.EscNone { + // If we allocated on the heap with ONEW, copy the static to the + // heap (4). We skip this for stack temporaries, because + // initStackTemp already handled the copy. a = ir.NewStarExpr(base.Pos, vauto) appendWalkStmt(init, ir.NewAssignStmt(base.Pos, a, vstat)) } @@ -535,7 +532,7 @@ func anylit(n ir.Node, var_ ir.Node, init *ir.Nodes) { var r ir.Node if n.Prealloc != nil { // n.Prealloc is stack temporary used as backing store. - r = initStackTemp(init, n.Prealloc, false) + r = initStackTemp(init, n.Prealloc, nil) } else { r = ir.NewUnaryExpr(base.Pos, ir.ONEW, ir.TypeNode(n.X.Type())) r.SetEsc(n.Esc()) |