From: Cuong Manh Le Date: Thu, 5 Feb 2026 14:16:55 +0000 (+0700) Subject: cmd/compile: fix SIMD type parameter instantiation X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=38ed6147485232f9562e87970c56f4491c082998;p=gostls13.git cmd/compile: fix SIMD type parameter instantiation When a SIMD type is used to instantiate a type parameter, the SIMD's underlying type is its shape. This shape type must be marked as a SIMD type, otherwise, the backend will confuse and does not know how to put this SIMD type to proper registers. Fixing this by marking a type as SIMD type if its underlying is already a SIMD one. Fixes #77444 Change-Id: I745c474469889c94bc68435472ba4820e9f752a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/742320 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Auto-Submit: Cuong Manh Le Reviewed-by: Michael Knyszek --- diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index 6663c49dd8..3fa0b90e12 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -1683,6 +1683,9 @@ func (t *Type) SetUnderlying(underlying *Type) { if underlying.HasShape() { t.SetHasShape(true) } + if underlying.isSIMD { + simdify(t, underlying.isSIMDTag) + } // spec: "The declared type does not inherit any methods bound // to the existing type, but the method set of an interface diff --git a/src/simd/archsimd/internal/simd_test/simd_test.go b/src/simd/archsimd/internal/simd_test/simd_test.go index 36bde92455..b28b990ed5 100644 --- a/src/simd/archsimd/internal/simd_test/simd_test.go +++ b/src/simd/archsimd/internal/simd_test/simd_test.go @@ -1440,3 +1440,24 @@ func TestSaturateConcat(t *testing.T) { }) } } + +func stringy[T interface{ String() string }](v T) string { + return v.String() +} + +func double[T interface{ Add(T) T }](v T) T { + return v.Add(v) +} + +// Test that vector type instantiation works correctly, see issue #77444. +func TestTypeParam(t *testing.T) { + x := archsimd.LoadInt64x2Slice([]int64{1, 1}) + y := archsimd.LoadInt64x2Slice([]int64{1, 1}) + if got := stringy(x); got != y.String() { + t.Fatalf("string(x) = %q, want %q", got, y.String()) + } + want := y.Add(y) + if got := double(x); got.NotEqual(want).ToBits() != 0 { + t.Fatalf("double(x) = %v, want %v", got, want) + } +}