mirror of
https://github.com/golang/go
synced 2024-11-23 21:20:03 -07:00
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 <rsc@golang.org>
This commit is contained in:
parent
4a1957d0aa
commit
f90d802b61
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user