Commit 700f979d23 for golang

commit 700f979d23831ed43e937d40e92b84c63819a86b
Author: Michael Haddon <michael@politepixels.io>
Date:   Thu Nov 26 05:16:43 2026 +0000

    cmd/compile: move float-int conversion results to GP registers on mips

    On mips and mips64, TRUNCFW, TRUNCDW, TRUNCFV and TRUNCDV leave their
    integer result in a floating-point register, and truncating it to 8 or
    16 bits is only a copy. A narrow integer converted from a float can
    then be a phi in a floating-point register. storeByType spills such a
    value with an 8-byte MOVD into its 1- or 2-byte stack slot, which
    faults or overwrites the neighbouring slots. For example, an int16
    converted from a float64 in one branch of an if and live across a call
    was spilled with MOVD F0, r-2(SP).

    Move the results to integer registers with MOVWfpgp and MOVVfpgp, and
    the inputs of the int-to-float conversions to floating-point registers
    with MOVWgpfp and MOVVgpfp, as CL 820040 did for loong64.

    Add a test.

    Fixes #83408

    Change-Id: I31c46cb187f7980eb66fdc6a9590bbd104704215
    GitHub-Last-Rev: 3a462b2da0483b61bece4824c1f1573419c1649b
    GitHub-Pull-Request: golang/go#83410
    Reviewed-on: https://go-review.googlesource.com/c/go/+/867306
    Reviewed-by: Keith Randall <khr@golang.org>
    Auto-Submit: Keith Randall <khr@golang.org>
    Reviewed-by: David Chase <drchase@google.com>
    Reviewed-by: Keith Randall <khr@google.com>
    LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

diff --git a/src/cmd/compile/internal/ssa/_gen/MIPS.rules b/src/cmd/compile/internal/ssa/_gen/MIPS.rules
index 7878fb3665..9e007f430a 100644
--- a/src/cmd/compile/internal/ssa/_gen/MIPS.rules
+++ b/src/cmd/compile/internal/ssa/_gen/MIPS.rules
@@ -179,8 +179,8 @@
 (Slicemask <t> x) => (SRAconst (NEG <t> x) [31])

 // float-int conversion
-(Cvt32to(32|64)F ...) => (MOVW(F|D) ...)
-(Cvt(32|64)Fto32 ...) => (TRUNC(F|D)W ...)
+(Cvt32to(32|64)F <t> x) => (MOVW(F|D) (MOVWgpfp <t> x))
+(Cvt(32|64)Fto32 <t> x) => (MOVWfpgp (TRUNC(F|D)W <t> x))
 (Cvt32Fto64F ...) => (MOVFD ...)
 (Cvt64Fto32F ...) => (MOVDF ...)

diff --git a/src/cmd/compile/internal/ssa/_gen/MIPS64.rules b/src/cmd/compile/internal/ssa/_gen/MIPS64.rules
index f8a1c44b9b..8638a9e22a 100644
--- a/src/cmd/compile/internal/ssa/_gen/MIPS64.rules
+++ b/src/cmd/compile/internal/ssa/_gen/MIPS64.rules
@@ -193,14 +193,14 @@
 (SignExt32to64 ...) => (MOVWreg ...)

 // float <=> int conversion
-(Cvt32to32F ...) => (MOVWF ...)
-(Cvt32to64F ...) => (MOVWD ...)
-(Cvt64to32F ...) => (MOVVF ...)
-(Cvt64to64F ...) => (MOVVD ...)
-(Cvt32Fto32 ...) => (TRUNCFW ...)
-(Cvt64Fto32 ...) => (TRUNCDW ...)
-(Cvt32Fto64 ...) => (TRUNCFV ...)
-(Cvt64Fto64 ...) => (TRUNCDV ...)
+(Cvt32to32F <t> x) => (MOVWF (MOVWgpfp <t> x))
+(Cvt32to64F <t> x) => (MOVWD (MOVWgpfp <t> x))
+(Cvt64to32F <t> x) => (MOVVF (MOVVgpfp <t> x))
+(Cvt64to64F <t> x) => (MOVVD (MOVVgpfp <t> x))
+(Cvt32Fto32 <t> x) => (MOVWfpgp (TRUNCFW <t> x))
+(Cvt64Fto32 <t> x) => (MOVWfpgp (TRUNCDW <t> x))
+(Cvt32Fto64 <t> x) => (MOVVfpgp (TRUNCFV <t> x))
+(Cvt64Fto64 <t> x) => (MOVVfpgp (TRUNCDV <t> x))
 (Cvt32Fto64F ...) => (MOVFD ...)
 (Cvt64Fto32F ...) => (MOVDF ...)

diff --git a/src/cmd/compile/internal/ssa/rewrite/mips/rewriteMIPS.go b/src/cmd/compile/internal/ssa/rewrite/mips/rewriteMIPS.go
index 6b819062ee..33015c7bcb 100644
--- a/src/cmd/compile/internal/ssa/rewrite/mips/rewriteMIPS.go
+++ b/src/cmd/compile/internal/ssa/rewrite/mips/rewriteMIPS.go
@@ -130,20 +130,16 @@ func RewriteValue(v *ssa.Value) bool {
 	case ssaop.OpCtz8NonZero:
 		return rewriteValue_OpCtz8NonZero(v)
 	case ssaop.OpCvt32Fto32:
-		v.Op = ssaop.OpMIPSTRUNCFW
-		return true
+		return rewriteValue_OpCvt32Fto32(v)
 	case ssaop.OpCvt32Fto64F:
 		v.Op = ssaop.OpMIPSMOVFD
 		return true
 	case ssaop.OpCvt32to32F:
-		v.Op = ssaop.OpMIPSMOVWF
-		return true
+		return rewriteValue_OpCvt32to32F(v)
 	case ssaop.OpCvt32to64F:
-		v.Op = ssaop.OpMIPSMOVWD
-		return true
+		return rewriteValue_OpCvt32to64F(v)
 	case ssaop.OpCvt64Fto32:
-		v.Op = ssaop.OpMIPSTRUNCDW
-		return true
+		return rewriteValue_OpCvt64Fto32(v)
 	case ssaop.OpCvt64Fto32F:
 		v.Op = ssaop.OpMIPSMOVDF
 		return true
@@ -1052,6 +1048,66 @@ func rewriteValue_OpCtz8NonZero(v *ssa.Value) bool {
 		return true
 	}
 }
+func rewriteValue_OpCvt32Fto32(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32Fto32 <t> x)
+	// result: (MOVWfpgp (TRUNCFW <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPSMOVWfpgp)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPSTRUNCFW, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt32to32F(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32to32F <t> x)
+	// result: (MOVWF (MOVWgpfp <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPSMOVWF)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPSMOVWgpfp, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt32to64F(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32to64F <t> x)
+	// result: (MOVWD (MOVWgpfp <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPSMOVWD)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPSMOVWgpfp, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt64Fto32(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt64Fto32 <t> x)
+	// result: (MOVWfpgp (TRUNCDW <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPSMOVWfpgp)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPSTRUNCDW, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
 func rewriteValue_OpDiv16(v *ssa.Value) bool {
 	v_1 := v.Args[1]
 	v_0 := v.Args[0]
diff --git a/src/cmd/compile/internal/ssa/rewrite/mips64/rewriteMIPS64.go b/src/cmd/compile/internal/ssa/rewrite/mips64/rewriteMIPS64.go
index be4d5f4ce8..7a8179d820 100644
--- a/src/cmd/compile/internal/ssa/rewrite/mips64/rewriteMIPS64.go
+++ b/src/cmd/compile/internal/ssa/rewrite/mips64/rewriteMIPS64.go
@@ -143,35 +143,27 @@ func RewriteValue(v *ssa.Value) bool {
 	case ssaop.OpConstNil:
 		return rewriteValue_OpConstNil(v)
 	case ssaop.OpCvt32Fto32:
-		v.Op = ssaop.OpMIPS64TRUNCFW
-		return true
+		return rewriteValue_OpCvt32Fto32(v)
 	case ssaop.OpCvt32Fto64:
-		v.Op = ssaop.OpMIPS64TRUNCFV
-		return true
+		return rewriteValue_OpCvt32Fto64(v)
 	case ssaop.OpCvt32Fto64F:
 		v.Op = ssaop.OpMIPS64MOVFD
 		return true
 	case ssaop.OpCvt32to32F:
-		v.Op = ssaop.OpMIPS64MOVWF
-		return true
+		return rewriteValue_OpCvt32to32F(v)
 	case ssaop.OpCvt32to64F:
-		v.Op = ssaop.OpMIPS64MOVWD
-		return true
+		return rewriteValue_OpCvt32to64F(v)
 	case ssaop.OpCvt64Fto32:
-		v.Op = ssaop.OpMIPS64TRUNCDW
-		return true
+		return rewriteValue_OpCvt64Fto32(v)
 	case ssaop.OpCvt64Fto32F:
 		v.Op = ssaop.OpMIPS64MOVDF
 		return true
 	case ssaop.OpCvt64Fto64:
-		v.Op = ssaop.OpMIPS64TRUNCDV
-		return true
+		return rewriteValue_OpCvt64Fto64(v)
 	case ssaop.OpCvt64to32F:
-		v.Op = ssaop.OpMIPS64MOVVF
-		return true
+		return rewriteValue_OpCvt64to32F(v)
 	case ssaop.OpCvt64to64F:
-		v.Op = ssaop.OpMIPS64MOVVD
-		return true
+		return rewriteValue_OpCvt64to64F(v)
 	case ssaop.OpCvtBoolToUint8:
 		v.Op = ssaop.OpCopy
 		return true
@@ -1062,6 +1054,126 @@ func rewriteValue_OpConstNil(v *ssa.Value) bool {
 		return true
 	}
 }
+func rewriteValue_OpCvt32Fto32(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32Fto32 <t> x)
+	// result: (MOVWfpgp (TRUNCFW <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVWfpgp)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64TRUNCFW, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt32Fto64(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32Fto64 <t> x)
+	// result: (MOVVfpgp (TRUNCFV <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVVfpgp)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64TRUNCFV, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt32to32F(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32to32F <t> x)
+	// result: (MOVWF (MOVWgpfp <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVWF)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64MOVWgpfp, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt32to64F(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt32to64F <t> x)
+	// result: (MOVWD (MOVWgpfp <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVWD)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64MOVWgpfp, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt64Fto32(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt64Fto32 <t> x)
+	// result: (MOVWfpgp (TRUNCDW <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVWfpgp)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64TRUNCDW, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt64Fto64(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt64Fto64 <t> x)
+	// result: (MOVVfpgp (TRUNCDV <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVVfpgp)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64TRUNCDV, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt64to32F(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt64to32F <t> x)
+	// result: (MOVVF (MOVVgpfp <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVVF)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64MOVVgpfp, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
+func rewriteValue_OpCvt64to64F(v *ssa.Value) bool {
+	v_0 := v.Args[0]
+	b := v.Block
+	// match: (Cvt64to64F <t> x)
+	// result: (MOVVD (MOVVgpfp <t> x))
+	for {
+		t := v.Type
+		x := v_0
+		v.Reset(ssaop.OpMIPS64MOVVD)
+		v0 := b.NewValue0(v.Pos, ssaop.OpMIPS64MOVVgpfp, t)
+		v0.AddArg(x)
+		v.AddArg(v0)
+		return true
+	}
+}
 func rewriteValue_OpDiv16(v *ssa.Value) bool {
 	v_1 := v.Args[1]
 	v_0 := v.Args[0]
diff --git a/test/fixedbugs/issue83408.go b/test/fixedbugs/issue83408.go
new file mode 100644
index 0000000000..ed8b27197b
--- /dev/null
+++ b/test/fixedbugs/issue83408.go
@@ -0,0 +1,30 @@
+// run
+
+// Copyright 2026 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
+
+//go:noinline
+func g() {}
+
+//go:noinline
+func f(c bool, x float64, y float32) (int16, uint8) {
+	a, b := int16(7), uint8(7)
+	if c {
+		a, b = int16(x), uint8(y)
+	}
+	g()
+	return a, b
+}
+
+func main() {
+	a, b := f(true, 1000, 200)
+	if a != 1000 {
+		panic(a)
+	}
+	if b != 200 {
+		panic(b)
+	}
+}