]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.simd] cmd/compile: handle rematerialized op for incompatible reg constraint
authorJunyang Shao <shaojunyang@google.com>
Tue, 16 Sep 2025 03:27:41 +0000 (03:27 +0000)
committerJunyang Shao <shaojunyang@google.com>
Thu, 18 Sep 2025 18:06:57 +0000 (11:06 -0700)
This CL fixes an issue raised by contributor dominikh@.

Change-Id: I941b330a6ba6f6c120c69951ddd24933f2f0b3ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/704056
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/regalloc.go
test/simd/bug2.go [new file with mode: 0644]

index 7ed5bda28cee11f8ec07b507105e199656a6c8de..fe30b89cdd660444aa7304eed3900e3a0dbfa35b 100644 (file)
@@ -2576,7 +2576,26 @@ func (e *edgeState) processDest(loc Location, vid ID, splice **Value, pos src.XP
                        e.s.f.Fatalf("can't find source for %s->%s: %s\n", e.p, e.b, v.LongString())
                }
                if dstReg {
-                       x = v.copyInto(e.p)
+                       // Handle incompatible registers.
+                       // For #70451.
+                       if e.s.regspec(v).outputs[0].regs&regMask(1<<register(loc.(*Register).num)) == 0 && c != nil {
+                               _, srcReg := src.(*Register)
+                               if !srcReg {
+                                       // We need a tmp register
+                                       x = v.copyInto(e.p)
+                                       r := e.findRegFor(x.Type)
+                                       e.erase(r)
+                                       // Rematerialize to a tmp register
+                                       e.set(r, vid, x, false, pos)
+                                       // Copy from tmp to the desired register
+                                       x = e.p.NewValue1(pos, OpCopy, x.Type, x)
+                               } else {
+                                       // It exist in a valid register already, so just copy it to the desired register
+                                       x = e.p.NewValue1(pos, OpCopy, c.Type, c)
+                               }
+                       } else {
+                               x = v.copyInto(e.p)
+                       }
                } else {
                        // Rematerialize into stack slot. Need a free
                        // register to accomplish this.
diff --git a/test/simd/bug2.go b/test/simd/bug2.go
new file mode 100644 (file)
index 0000000..2d2094b
--- /dev/null
@@ -0,0 +1,26 @@
+// compile
+
+//go:build amd64 && goexperiment.simd
+
+// 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.
+
+// Test case for rematerialization ignoring the register constraint
+// during regalloc's shuffle phase.
+
+package p
+
+import (
+       "simd"
+)
+
+func PackComplex(b bool) {
+       for {
+               if b {
+                       var indices [4]uint32
+                       simd.Uint32x4{}.ShiftAllRight(20).Store(&indices)
+                       _ = indices[indices[0]]
+               }
+       }
+}