]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove walkReturn "common case" path
authorMatthew Dempsky <mdempsky@google.com>
Sun, 3 Jan 2021 08:03:28 +0000 (00:03 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 3 Jan 2021 19:48:17 +0000 (19:48 +0000)
After the previous two optimization CLs, this code path now generates
the same code as ascompatee does anyway. So just use that and remove
some redundant code.

Passes toolstash -cmp.

Change-Id: I5e2e5c6dbea64d8e91abe0f2cf51aa5bb86576d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/281154
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>
src/cmd/compile/internal/walk/assign.go

index 84ba7f0dc5093dccf25c01c0f89056f54c88f584..ec0f60ad9357122b87434e555801a5931d696adb 100644 (file)
@@ -143,7 +143,7 @@ func walkAssignFunc(init *ir.Nodes, n *ir.AssignListStmt) ir.Node {
 // walkAssignList walks an OAS2 node.
 func walkAssignList(init *ir.Nodes, n *ir.AssignListStmt) ir.Node {
        init.Append(ir.TakeInit(n)...)
-       return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs, init))
+       return ir.NewBlockStmt(src.NoXPos, ascompatee(ir.OAS, n.Lhs, n.Rhs))
 }
 
 // walkAssignMapRead walks an OAS2MAPR node.
@@ -244,20 +244,7 @@ func walkReturn(n *ir.ReturnStmt) ir.Node {
                dsts[i] = typecheck.AssignExpr(v.Nname.(*ir.Name))
        }
 
-       if (ir.HasNamedResults(fn) && len(n.Results) > 1) || paramoutheap(fn) {
-               // General case: For anything tricky, let ascompatee handle
-               // ordering the assignments correctly.
-               n.Results = ascompatee(n.Op(), dsts, n.Results, n.PtrInit())
-               return n
-       }
-
-       // Common case: Assignment order doesn't matter. Simply assign to
-       // each result parameter in order.
-       var res ir.Nodes
-       for i, v := range n.Results {
-               appendWalkStmt(&res, convas(ir.NewAssignStmt(base.Pos, dsts[i], v), &res))
-       }
-       n.Results = res
+       n.Results = ascompatee(n.Op(), dsts, n.Results)
        return n
 }
 
@@ -318,7 +305,7 @@ func ascompatet(nl ir.Nodes, nr *types.Type) []ir.Node {
 // check assign expression list to
 // an expression list. called in
 //     expr-list = expr-list
-func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node {
+func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node {
        // cannot happen: should have been rejected during type checking
        if len(nl) != len(nr) {
                base.Fatalf("assignment operands mismatch: %+v / %+v", ir.Nodes(nl), ir.Nodes(nr))
@@ -413,6 +400,11 @@ func ascompatee(op ir.Op, nl, nr []ir.Node, init *ir.Nodes) []ir.Node {
                        // We can ignore assignments to blank.
                        continue
                }
+               if op == ir.ORETURN && types.OrigSym(name.Sym()) == nil {
+                       // We can also ignore assignments to anonymous result
+                       // parameters. These can't appear in expressions anyway.
+                       continue
+               }
                assigned.Add(name)
        }