From f90d802b6102ced82377ddc16f81f299c039ce83 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 27 May 2015 15:20:49 -0400 Subject: [PATCH] cmd/compile: avoid temporary in race mode with slice and append Currently when the race detector is enabled, orderexpr always creates a temporary for slice and append operations. This used to be necessary because the race detector had a different code path for slice assignment that required this temporary. Unfortunately, creating this temporary inhibits the optimization that eliminates write barriers when a slice is assigned only to change its length or cap. For most code, this is bad for performance, and in go:nowritebarrier functions in the runtime, this can mean the difference between compiling and not compiling. Now the race detector uses the regular slice assignment code, so creating this temporary is no longer necessary. Change-Id: I296042e1edc571b77c407f709c2ff9091c4aa795 Reviewed-on: https://go-review.googlesource.com/10456 Reviewed-by: Russ Cox --- src/cmd/compile/internal/gc/order.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/gc/order.go b/src/cmd/compile/internal/gc/order.go index 8b99ed0895..ee0ec52e7b 100644 --- a/src/cmd/compile/internal/gc/order.go +++ b/src/cmd/compile/internal/gc/order.go @@ -1090,7 +1090,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { case OAPPEND: ordercallargs(&n.List, order) - if lhs == nil || flag_race != 0 || lhs.Op != ONAME && !samesafeexpr(lhs, n.List.N) { + if lhs == nil || lhs.Op != ONAME && !samesafeexpr(lhs, n.List.N) { n = ordercopyexpr(n, n.Type, order, 0) } @@ -1100,7 +1100,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { n.Right.Left = ordercheapexpr(n.Right.Left, order) orderexpr(&n.Right.Right, order, nil) n.Right.Right = ordercheapexpr(n.Right.Right, order) - if lhs == nil || flag_race != 0 || lhs.Op != ONAME && !samesafeexpr(lhs, n.Left) { + if lhs == nil || lhs.Op != ONAME && !samesafeexpr(lhs, n.Left) { n = ordercopyexpr(n, n.Type, order, 0) } @@ -1112,7 +1112,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { n.Right.Right.Left = ordercheapexpr(n.Right.Right.Left, order) orderexpr(&n.Right.Right.Right, order, nil) n.Right.Right.Right = ordercheapexpr(n.Right.Right.Right, order) - if lhs == nil || flag_race != 0 || lhs.Op != ONAME && !samesafeexpr(lhs, n.Left) { + if lhs == nil || lhs.Op != ONAME && !samesafeexpr(lhs, n.Left) { n = ordercopyexpr(n, n.Type, order, 0) } -- 2.50.0