From 365911de24d7d54ce29b6d11ad714e772e3e82ee Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 15 Jun 2017 10:28:26 -0400 Subject: [PATCH] go/ssa: opt: avoid an allocation In the dom tree traversal, the final child of each node now inherits the parent's renaming map, reducing garbage. This reduces allocations by 1.4% and bytes allocated by 2.0% when building SSA for the entire standard library. Change-Id: Id19b6d6766b3e0bf32d1db1238eff8a42d11b242 Reviewed-on: https://go-review.googlesource.com/45833 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- go/ssa/lift.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/go/ssa/lift.go b/go/ssa/lift.go index 091992f0..00c8a723 100644 --- a/go/ssa/lift.go +++ b/go/ssa/lift.go @@ -630,10 +630,15 @@ func rename(u *BasicBlock, renaming []Value, newPhis newPhiMap) { // Continue depth-first recursion over domtree, pushing a // fresh copy of the renaming map for each subtree. - for _, v := range u.dom.children { - // TODO(adonovan): opt: avoid copy on final iteration; use destructive update. - r := make([]Value, len(renaming)) - copy(r, renaming) + for i, v := range u.dom.children { + r := renaming + if i < len(u.dom.children)-1 { + // On all but the final iteration, we must make + // a copy to avoid destructive update. + r = make([]Value, len(renaming)) + copy(r, renaming) + } rename(v, r, newPhis) } + }