From: Matthew Dempsky Date: Sun, 3 Jan 2021 07:56:20 +0000 (-0800) Subject: [dev.regabi] cmd/compile: improve walkReturn common case X-Git-Tag: go1.17beta1~1539^2~143 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d36a6bf44da6d9b6e1ec355381ef15d253435e20;p=gostls13.git [dev.regabi] cmd/compile: improve walkReturn common case Instead of evaluating all result expressions up front and then assigning them to their result destinations, we can interleave evaluation with assignment. This reduces how much temporary stack/register space is needed to hold the values in flight. Doesn't pass toolstash -cmp, because it allows better return statement code to be generated. E.g., cmd/go's text segment on linux/ppc64le shrinks another 1kB. Change-Id: I3fe889342c80e947e0118704ec01f1682c577e6e Reviewed-on: https://go-review.googlesource.com/c/go/+/281153 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go index 04bd576b69..84ba7f0dc5 100644 --- a/src/cmd/compile/internal/walk/assign.go +++ b/src/cmd/compile/internal/walk/assign.go @@ -253,10 +253,9 @@ func walkReturn(n *ir.ReturnStmt) ir.Node { // Common case: Assignment order doesn't matter. Simply assign to // each result parameter in order. - walkExprList(n.Results, n.PtrInit()) - res := make([]ir.Node, len(results)) + var res ir.Nodes for i, v := range n.Results { - res[i] = convas(ir.NewAssignStmt(base.Pos, dsts[i], v), n.PtrInit()) + appendWalkStmt(&res, convas(ir.NewAssignStmt(base.Pos, dsts[i], v), &res)) } n.Results = res return n