]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix SIMD type parameter instantiation
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 5 Feb 2026 14:16:55 +0000 (21:16 +0700)
committerGopher Robot <gobot@golang.org>
Fri, 6 Feb 2026 17:36:03 +0000 (09:36 -0800)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/compile/internal/types/type.go
src/simd/archsimd/internal/simd_test/simd_test.go

index 6663c49dd8d8a9ec9cf77f4713887ddd433bfc6b..3fa0b90e12938e19605b0b901e788235098efc4e 100644 (file)
@@ -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
index 36bde92455538174f6afae9526300e67bea64834..b28b990ed5887feb4a1f236cfb05d00b7aa56595 100644 (file)
@@ -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)
+       }
+}