Commit f583847c0b for golang

commit f583847c0b6c2bd1de999aa902a93121e0432356
Author: Austin Clements <austin@google.com>
Date:   Wed Nov 25 11:04:05 2026 -0500

    cmd/compile: fix fallback rules for 512-bit IsNaN().Or(IsNaN())

    The rules that fold x.IsNaN().Or(y.IsNaN()) on 512-bit vectors into one
    unordered comparison have fallbacks in case the Or is first rewritten to
    an operation on K registers. But the fallbacks match KANDB and KANDW, not
    KORB and KORW. So they instead fired on x.IsNaN().And(y.IsNaN()), even
    though they still rewrote it as if it were x.IsNaN().Or(y.IsNaN()). On
    Float32x16, that computed whether x or y has a NaN. On Float64x8, it
    computed just x.IsNaN(), because that fallback also dropped y.

    Make the fallbacks match KORB and KORW, and test And of IsNaN masks too.

    Change-Id: I557141391dd78638ca82d665811302f86a6a6964
    Reviewed-on: https://go-review.googlesource.com/c/go/+/868741
    Reviewed-by: David Chase <drchase@google.com>
    LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
    Auto-Submit: Austin Clements <austin@google.com>

diff --git a/src/simd/archsimd/internal/simd_test/compare_amd64_test.go b/src/simd/archsimd/internal/simd_test/compare_amd64_test.go
index 8d4e8330a4..fae314ae45 100644
--- a/src/simd/archsimd/internal/simd_test/compare_amd64_test.go
+++ b/src/simd/archsimd/internal/simd_test/compare_amd64_test.go
@@ -246,6 +246,28 @@ func TestIsNaN(t *testing.T) {
 				return x.IsNaN().Or(y.IsNaN())
 			}, want64)
 	}
+
+	// Test x.IsNaN().And(y.IsNaN()).
+	wantAnd32 := mapCompare(func(x, y float32) bool { return x != x && y != y })
+	wantAnd64 := mapCompare(func(x, y float64) bool { return x != x && y != y })
+	testFloat32x4Compare(t,
+		func(x, y archsimd.Float32x4) archsimd.Mask32x4 {
+			return x.IsNaN().And(y.IsNaN())
+		}, wantAnd32)
+	testFloat64x2Compare(t,
+		func(x, y archsimd.Float64x2) archsimd.Mask64x2 {
+			return x.IsNaN().And(y.IsNaN())
+		}, wantAnd64)
+	if archsimd.X86.AVX512() {
+		testFloat32x16Compare(t,
+			func(x, y archsimd.Float32x16) archsimd.Mask32x16 {
+				return x.IsNaN().And(y.IsNaN())
+			}, wantAnd32)
+		testFloat64x8Compare(t,
+			func(x, y archsimd.Float64x8) archsimd.Mask64x8 {
+				return x.IsNaN().And(y.IsNaN())
+			}, wantAnd64)
+	}
 }

 //go:noinline
diff --git a/test/codegen/simd.go b/test/codegen/simd.go
index 69f970fee7..96a3afd50d 100644
--- a/test/codegen/simd.go
+++ b/test/codegen/simd.go
@@ -291,6 +291,17 @@ func simdIsNaN512() {
 	c.ToInt64x8().Store(sinkInt64s)
 }

+func simdIsNaNAnd512(x, y archsimd.Float64x8) archsimd.Mask64x8 {
+	// Unlike Or, And of IsNaN masks can't be one comparison.
+	// amd64:"VCMPPD [$]3, Z0, Z0" "VCMPPD [$]3, Z1, Z1" "KANDB"
+	return x.IsNaN().And(y.IsNaN())
+}
+
+func simdIsNaNAnd512S(x, y archsimd.Float32x16) archsimd.Mask32x16 {
+	// amd64:"VCMPPS [$]3, Z0, Z0" "VCMPPS [$]3, Z1, Z1" "KANDW"
+	return x.IsNaN().And(y.IsNaN())
+}
+
 func sftImmVPSRL() archsimd.Uint32x4 {
 	var x archsimd.Uint32x4
 	// amd64:`VPSRLD \$1, .*$`