cmd/compile: move writebarrier pass after dse
This avoids generating writeBarrier.enabled
blocks for dead stores.
Change-Id: Ib11d8e2ba952f3f1f01d16776e40a7200a7683cf
Reviewed-on: https://go-review.googlesource.com/42012
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/test/writebarrier.go b/test/writebarrier.go
index 13f7b54..f3149e1 100644
--- a/test/writebarrier.go
+++ b/test/writebarrier.go
@@ -11,14 +11,14 @@
import "unsafe"
func f(x **byte, y *byte) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f1(x *[]byte, y []byte) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
@@ -32,21 +32,21 @@
}
func f2(x *interface{}, y interface{}) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f2a(x *interface{}, y *interface{}) {
- *x = *y // ERROR "write barrier"
+ *x = *y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
}
func f3(x *string, y string) {
- *x = y // ERROR "write barrier"
+ *x = y // no barrier (dead store)
z := y // no barrier
*x = z // ERROR "write barrier"
@@ -204,12 +204,18 @@
}
var z21 int
-func f21(x *int) {
- // Global -> heap pointer updates must have write barriers.
- x21 = x // ERROR "write barrier"
- y21.x = x // ERROR "write barrier"
- x21 = &z21 // ERROR "write barrier"
- y21.x = &z21 // ERROR "write barrier"
+// f21x: Global -> heap pointer updates must have write barriers.
+func f21a(x *int) {
+ x21 = x // ERROR "write barrier"
+ y21.x = x // ERROR "write barrier"
+}
+
+func f21b(x *int) {
+ x21 = &z21 // ERROR "write barrier"
+ y21.x = &z21 // ERROR "write barrier"
+}
+
+func f21c(x *int) {
y21 = struct{ x *int }{x} // ERROR "write barrier"
}
@@ -229,10 +235,15 @@
var t23 T23
var i23 int
-func f23() {
- // zeroing global needs write barrier for the hybrid barrier.
+// f23x: zeroing global needs write barrier for the hybrid barrier.
+func f23a() {
t23 = T23{} // ERROR "write barrier"
// also test partial assignments
- t23 = T23{a: 1} // ERROR "write barrier"
+ t23 = T23{a: 1} // ERROR "write barrier"
+}
+
+func f23b() {
+ t23 = T23{} // no barrier (dead store)
+ // also test partial assignments
t23 = T23{p: &i23} // ERROR "write barrier"
}