cmd/compile: enforce nowritebarrier in SSA compiler
Make sure we don't generate write barriers in runtime
code that is marked to forbid write barriers.
Implement the optimization that if we're writing a sliced
slice back to the location it came from, we don't need a
write barrier.
Fixes #14784
Change-Id: I04b6a3b2ac303c19817e932a36a3b006de103aaa
Reviewed-on: https://go-review.googlesource.com/20791
Reviewed-by: Austin Clements <austin@google.com>
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 6d136f6..3b36457 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -2146,6 +2146,13 @@
return false
}
+ // No write barrier for writing a sliced slice back to its
+ // original location.
+ if (r.Op == OSLICE || r.Op == OSLICE3 || r.Op == OSLICESTR) &&
+ samesafeexpr(r.Left, l) {
+ return false
+ }
+
// Otherwise, be conservative and use write barrier.
return true
}