Commit f90d802b authored by Austin Clements's avatar Austin Clements

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/10456Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 4a1957d0
......@@ -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)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment