]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.24] cmd/compile: ensure we don't reuse temporary register
authorkhr@golang.org <khr@golang.org>
Sun, 23 Feb 2025 18:34:00 +0000 (10:34 -0800)
committerMichael Pratt <mpratt@google.com>
Wed, 26 Feb 2025 17:43:51 +0000 (09:43 -0800)
Before this CL, we could use the same register for both a temporary
register and for moving a value in the output register out of the way.

Fixes #71904

Change-Id: Iefbfd9d4139136174570d8aadf8a0fb391791ea9
Reviewed-on: https://go-review.googlesource.com/c/go/+/651221
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
(cherry picked from commit cc16fb52e6f1eafaee468f8563525ec391e016f5)
Reviewed-on: https://go-review.googlesource.com/c/go/+/652178

src/cmd/compile/internal/ssa/regalloc.go
test/fixedbugs/issue71857.go [new file with mode: 0644]

index 08ce0d16a63bba3994874d167fe2b6e344b680b9..c9f041639852c7c56d7a62a324fb5302f89d985b 100644 (file)
@@ -1670,6 +1670,7 @@ func (s *regAllocState) regalloc(f *Func) {
                                }
                                tmpReg = s.allocReg(m, &tmpVal)
                                s.nospill |= regMask(1) << tmpReg
+                               s.tmpused |= regMask(1) << tmpReg
                        }
 
                        // Now that all args are in regs, we're ready to issue the value itself.
diff --git a/test/fixedbugs/issue71857.go b/test/fixedbugs/issue71857.go
new file mode 100644 (file)
index 0000000..34d2928
--- /dev/null
@@ -0,0 +1,29 @@
+// run
+
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "sync/atomic"
+
+//go:noinline
+func f(p0, p1, p2, p3, p4, p5, p6, p7 *uint64, a *atomic.Uint64) {
+       old := a.Or(0xaaa)
+       *p0 = old
+       *p1 = old
+       *p2 = old
+       *p3 = old
+       *p4 = old
+       *p5 = old
+       *p6 = old
+       *p7 = old
+}
+
+func main() {
+       a := new(atomic.Uint64)
+       p := new(uint64)
+       f(p, p, p, p, p, p, p, p, a)
+
+}