Skip to content

Commit 6b9e3f8

Browse files
zikaerohMartin Möhrmann
authored and
Martin Möhrmann
committed
cmd/compile: don't emit write barriers for offsets of global addresses
Currently, write barriers aren't emitted for global addresses, but they are emitted for addresses offset of global addresses. This CL changes IsGlobalAddr to recognize offsets of global addresses as globals too, removing write barriers for staticuint64s based addresses. The logic added is the same as used in IsStackAddr. Updates golang#37612 Change-Id: I537579f85b9ad02987d94f3ee0b4508b90097959 Reviewed-on: https://go-review.googlesource.com/c/go/+/342129 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Trust: Michael Knyszek <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 3081f81 commit 6b9e3f8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/cmd/compile/internal/ssa/writebarrier.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ func IsStackAddr(v *Value) bool {
552552

553553
// IsGlobalAddr reports whether v is known to be an address of a global (or nil).
554554
func IsGlobalAddr(v *Value) bool {
555+
for v.Op == OpOffPtr || v.Op == OpAddPtr || v.Op == OpPtrIndex || v.Op == OpCopy {
556+
v = v.Args[0]
557+
}
555558
if v.Op == OpAddr && v.Args[0].Op == OpSB {
556559
return true // address of a global
557560
}

test/writebarrier.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,17 @@ func f27(p *int) []interface{} {
289289
p, // ERROR "write barrier"
290290
}
291291
}
292+
293+
var g28 [256]uint64
294+
295+
func f28() []interface{} {
296+
return []interface{}{
297+
false, // no write barrier
298+
true, // no write barrier
299+
0, // no write barrier
300+
1, // no write barrier
301+
uint8(127), // no write barrier
302+
int8(-4), // no write barrier
303+
&g28[5], // no write barrier
304+
}
305+
}

0 commit comments

Comments
 (0)