]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: avoid temporary in race mode with slice and append
authorAustin Clements <austin@google.com>
Wed, 27 May 2015 19:20:49 +0000 (15:20 -0400)
committerAustin Clements <austin@google.com>
Thu, 28 May 2015 17:39:26 +0000 (17:39 +0000)
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 <rsc@golang.org>
src/cmd/compile/internal/gc/order.go

index 8b99ed089591530b2b564158229d89ebc9317bdd..ee0ec52e7bc583f2ac3873fba9a5316f9a974b18 100644 (file)
@@ -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)
                }