Commit e5c9358f authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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: default avatarCherry Zhang <cherryyz@google.com>
parent cf1b323f
...@@ -348,9 +348,9 @@ var passes = [...]pass{ ...@@ -348,9 +348,9 @@ var passes = [...]pass{
{name: "late opt", fn: opt, required: true}, // TODO: split required rules and optimizing rules {name: "late opt", fn: opt, required: true}, // TODO: split required rules and optimizing rules
{name: "generic deadcode", fn: deadcode}, {name: "generic deadcode", fn: deadcode},
{name: "check bce", fn: checkbce}, {name: "check bce", fn: checkbce},
{name: "writebarrier", fn: writebarrier, required: true}, // expand write barrier ops
{name: "fuse", fn: fuse}, {name: "fuse", fn: fuse},
{name: "dse", fn: dse}, {name: "dse", fn: dse},
{name: "writebarrier", fn: writebarrier, required: true}, // expand write barrier ops
{name: "insert resched checks", fn: insertLoopReschedChecks, {name: "insert resched checks", fn: insertLoopReschedChecks,
disabled: objabi.Preemptibleloops_enabled == 0}, // insert resched checks in loops. disabled: objabi.Preemptibleloops_enabled == 0}, // insert resched checks in loops.
{name: "tighten", fn: tighten}, // move values closer to their uses {name: "tighten", fn: tighten}, // move values closer to their uses
......
...@@ -11,14 +11,14 @@ package p ...@@ -11,14 +11,14 @@ package p
import "unsafe" import "unsafe"
func f(x **byte, y *byte) { func f(x **byte, y *byte) {
*x = y // ERROR "write barrier" *x = y // no barrier (dead store)
z := y // no barrier z := y // no barrier
*x = z // ERROR "write barrier" *x = z // ERROR "write barrier"
} }
func f1(x *[]byte, y []byte) { func f1(x *[]byte, y []byte) {
*x = y // ERROR "write barrier" *x = y // no barrier (dead store)
z := y // no barrier z := y // no barrier
*x = z // ERROR "write barrier" *x = z // ERROR "write barrier"
...@@ -32,21 +32,21 @@ func f1a(x *[]byte, y *[]byte) { ...@@ -32,21 +32,21 @@ func f1a(x *[]byte, y *[]byte) {
} }
func f2(x *interface{}, y interface{}) { func f2(x *interface{}, y interface{}) {
*x = y // ERROR "write barrier" *x = y // no barrier (dead store)
z := y // no barrier z := y // no barrier
*x = z // ERROR "write barrier" *x = z // ERROR "write barrier"
} }
func f2a(x *interface{}, y *interface{}) { func f2a(x *interface{}, y *interface{}) {
*x = *y // ERROR "write barrier" *x = *y // no barrier (dead store)
z := y // no barrier z := y // no barrier
*x = z // ERROR "write barrier" *x = z // ERROR "write barrier"
} }
func f3(x *string, y string) { func f3(x *string, y string) {
*x = y // ERROR "write barrier" *x = y // no barrier (dead store)
z := y // no barrier z := y // no barrier
*x = z // ERROR "write barrier" *x = z // ERROR "write barrier"
...@@ -204,12 +204,18 @@ var y21 struct { ...@@ -204,12 +204,18 @@ var y21 struct {
} }
var z21 int var z21 int
func f21(x *int) { // f21x: Global -> heap pointer updates must have write barriers.
// Global -> heap pointer updates must have write barriers. func f21a(x *int) {
x21 = x // ERROR "write barrier" x21 = x // ERROR "write barrier"
y21.x = x // ERROR "write barrier" y21.x = x // ERROR "write barrier"
}
func f21b(x *int) {
x21 = &z21 // ERROR "write barrier" x21 = &z21 // ERROR "write barrier"
y21.x = &z21 // ERROR "write barrier" y21.x = &z21 // ERROR "write barrier"
}
func f21c(x *int) {
y21 = struct{ x *int }{x} // ERROR "write barrier" y21 = struct{ x *int }{x} // ERROR "write barrier"
} }
...@@ -229,10 +235,15 @@ type T23 struct { ...@@ -229,10 +235,15 @@ type T23 struct {
var t23 T23 var t23 T23
var i23 int var i23 int
func f23() { // f23x: zeroing global needs write barrier for the hybrid barrier.
// zeroing global needs write barrier for the hybrid barrier. func f23a() {
t23 = T23{} // ERROR "write barrier" t23 = T23{} // ERROR "write barrier"
// also test partial assignments // 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" t23 = T23{p: &i23} // ERROR "write barrier"
} }
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