]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix SIMD const rematerialization condition
authorJunyang Shao <shaojunyang@google.com>
Fri, 19 Sep 2025 18:38:25 +0000 (18:38 +0000)
committerCherry Mui <cherryyz@google.com>
Fri, 3 Oct 2025 19:31:13 +0000 (12:31 -0700)
This CL fixes a condition for the previous fix CL 704056.

Cherry-picked from the dev.simd branch. This CL is not
necessarily SIMD specific. Apply early to reduce risk. Test is
SIMD specific so not included for now.

Change-Id: I1f1f8c6f72870403cb3dff14755c43385dc0c933
Reviewed-on: https://go-review.googlesource.com/c/go/+/705499
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/708864
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/regalloc.go

index 88861dfa14c8408aa6d2914a3359307d381629a7..e959b8ed7df2eb4b8d08e77af1cc9a8f3a345d34 100644 (file)
@@ -2561,22 +2561,25 @@ 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 {
-                       // Handle incompatible registers.
+                       // We want to rematerialize v into a register that is incompatible with v's op's register mask.
+                       // Instead of setting the wrong register for the rematerialized v, we should find the right register
+                       // for it and emit an additional copy to move to the desired register.
                        // For #70451.
-                       if e.s.regspec(v).outputs[0].regs&regMask(1<<register(loc.(*Register).num)) == 0 && c != nil {
+                       if e.s.regspec(v).outputs[0].regs&regMask(1<<register(loc.(*Register).num)) == 0 {
                                _, srcReg := src.(*Register)
-                               if !srcReg {
+                               if srcReg {
+                                       // It exists in a valid register already, so just copy it to the desired register
+                                       // If src is a Register, c must have already been set.
+                                       x = e.p.NewValue1(pos, OpCopy, c.Type, c)
+                               } else {
                                        // We need a tmp register
                                        x = v.copyInto(e.p)
                                        r := e.findRegFor(x.Type)
                                        e.erase(r)
-                                       // Rematerialize to a tmp register
+                                       // Rematerialize to the 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)