aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-01-10 17:33:26 -0800
committerKeith Randall <khr@golang.org>2025-01-12 22:49:39 -0800
commit44a6f817ea0fbeb3ba4aa398794c4e80dba13b1e (patch)
treebf8b97d89a07f0185ab42468d20b2e68887f4986 /src
parent19e923182e590ae6568c2c714f20f32512aeb3e3 (diff)
downloadgo-44a6f817ea0fbeb3ba4aa398794c4e80dba13b1e.tar.xz
cmd/compile: fix write barrier coalescing
We can't coalesce a non-WB store with a subsequent Move, as the result of the store might be the source of the move. There's a simple codegen test. Not sure how we might do a real test, as all the repro's I've come up with are very expensive and unreliable. Fixes #71228 Change-Id: If18bf181a266b9b90964e2591cd2e61a7168371c Reviewed-on: https://go-review.googlesource.com/c/go/+/642197 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ssa/writebarrier.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/writebarrier.go b/src/cmd/compile/internal/ssa/writebarrier.go
index 1caccb7c18..71acefbf8a 100644
--- a/src/cmd/compile/internal/ssa/writebarrier.go
+++ b/src/cmd/compile/internal/ssa/writebarrier.go
@@ -252,6 +252,7 @@ func writebarrier(f *Func) {
var start, end int
var nonPtrStores int
values := b.Values
+ hasMove := false
FindSeq:
for i := len(values) - 1; i >= 0; i-- {
w := values[i]
@@ -263,6 +264,9 @@ func writebarrier(f *Func) {
end = i + 1
}
nonPtrStores = 0
+ if w.Op == OpMoveWB {
+ hasMove = true
+ }
case OpVarDef, OpVarLive:
continue
case OpStore:
@@ -273,6 +277,17 @@ func writebarrier(f *Func) {
if nonPtrStores > 2 {
break FindSeq
}
+ if hasMove {
+ // We need to ensure that this store happens
+ // before we issue a wbMove, as the wbMove might
+ // use the result of this store as its source.
+ // Even though this store is not write-barrier
+ // eligible, it might nevertheless be the store
+ // of a pointer to the stack, which is then the
+ // source of the move.
+ // See issue 71228.
+ break FindSeq
+ }
default:
if last == nil {
continue