]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: don't emit write barriers for offsets of global addresses
authorzikaeroh <zikaeroh@gmail.com>
Fri, 30 Jul 2021 04:15:52 +0000 (21:15 -0700)
committerMartin Möhrmann <martin@golang.org>
Mon, 23 Aug 2021 19:46:36 +0000 (19:46 +0000)
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 #37612

Change-Id: I537579f85b9ad02987d94f3ee0b4508b90097959
Reviewed-on: https://go-review.googlesource.com/c/go/+/342129
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

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

index 419d91d0d367e609dcf9874cced1a58c04acdb4a..d7510965f6b31a6b9a3b83e76ab9ab1587834449 100644 (file)
@@ -552,6 +552,9 @@ func IsStackAddr(v *Value) bool {
 
 // IsGlobalAddr reports whether v is known to be an address of a global (or nil).
 func IsGlobalAddr(v *Value) bool {
+       for v.Op == OpOffPtr || v.Op == OpAddPtr || v.Op == OpPtrIndex || v.Op == OpCopy {
+               v = v.Args[0]
+       }
        if v.Op == OpAddr && v.Args[0].Op == OpSB {
                return true // address of a global
        }
index dbf0b6dde28662d0d6670037744c6611866e31a1..1b30fa509e5503275904c53fb7d559296ab85259 100644 (file)
@@ -289,3 +289,17 @@ func f27(p *int) []interface{} {
                p,           // ERROR "write barrier"
        }
 }
+
+var g28 [256]uint64
+
+func f28() []interface{} {
+       return []interface{}{
+               false,      // no write barrier
+               true,       // no write barrier
+               0,          // no write barrier
+               1,          // no write barrier
+               uint8(127), // no write barrier
+               int8(-4),   // no write barrier
+               &g28[5],    // no write barrier
+       }
+}