mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.simd] cmd/compile: make condtion of CanSSA smarter for SIMD fields
This CL tires to improve a situation pointed out by https://github.com/golang/go/issues/73787#issuecomment-3305494947. Change-Id: Ic23c80fe71344fc25383ab238ad6631e0f0cd22e Reviewed-on: https://go-review.googlesource.com/c/go/+/705416 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
c28b2a0ca1
commit
578777bf7c
3 changed files with 88 additions and 3 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"cmd/compile/internal/types"
|
||||
"cmd/internal/src"
|
||||
"fmt"
|
||||
"internal/buildcfg"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -615,12 +616,15 @@ func CanSSA(t *types.Type) bool {
|
|||
if t.IsSIMD() {
|
||||
return true
|
||||
}
|
||||
if t.Size() > int64(4*types.PtrSize) {
|
||||
sizeLimit := int64(MaxStruct * types.PtrSize)
|
||||
if t.Size() > sizeLimit {
|
||||
// 4*Widthptr is an arbitrary constant. We want it
|
||||
// to be at least 3*Widthptr so slices can be registerized.
|
||||
// Too big and we'll introduce too much register pressure.
|
||||
if !buildcfg.Experiment.SIMD {
|
||||
return false
|
||||
}
|
||||
}
|
||||
switch t.Kind() {
|
||||
case types.TARRAY:
|
||||
// We can't do larger arrays because dynamic indexing is
|
||||
|
|
@ -639,7 +643,17 @@ func CanSSA(t *types.Type) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
// Special check for SIMD. If the composite type
|
||||
// contains SIMD vectors we can return true
|
||||
// if it pass the checks below.
|
||||
if !buildcfg.Experiment.SIMD {
|
||||
return true
|
||||
}
|
||||
if t.Size() <= sizeLimit {
|
||||
return true
|
||||
}
|
||||
i, f := t.Registers()
|
||||
return i+f <= MaxStruct
|
||||
default:
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
41
src/cmd/compile/internal/test/value_test.go
Normal file
41
src/cmd/compile/internal/test/value_test.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2025 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 test
|
||||
|
||||
import (
|
||||
"cmd/compile/internal/ssa"
|
||||
"cmd/compile/internal/types"
|
||||
"internal/buildcfg"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// This file contains tests for ssa values, types and their utility functions.
|
||||
|
||||
func TestCanSSA(t *testing.T) {
|
||||
i64 := types.Types[types.TINT64]
|
||||
v128 := types.TypeVec128
|
||||
s1 := mkstruct(i64, mkstruct(i64, i64, i64, i64))
|
||||
if ssa.CanSSA(s1) {
|
||||
// Test size check for struct.
|
||||
t.Errorf("CanSSA(%v) returned true, expected false", s1)
|
||||
}
|
||||
a1 := types.NewArray(s1, 1)
|
||||
if ssa.CanSSA(a1) {
|
||||
// Test size check for array.
|
||||
t.Errorf("CanSSA(%v) returned true, expected false", a1)
|
||||
}
|
||||
if buildcfg.Experiment.SIMD {
|
||||
s2 := mkstruct(v128, v128, v128, v128)
|
||||
if !ssa.CanSSA(s2) {
|
||||
// Test size check for SIMD struct special case.
|
||||
t.Errorf("CanSSA(%v) returned false, expected true", s2)
|
||||
}
|
||||
a2 := types.NewArray(s2, 1)
|
||||
if !ssa.CanSSA(a2) {
|
||||
// Test size check for SIMD array special case.
|
||||
t.Errorf("CanSSA(%v) returned false, expected true", a2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,3 +27,33 @@ func vptest2() bool {
|
|||
// amd64:`SETEQ\s(.*)$`
|
||||
return v1.And(v2).IsZero()
|
||||
}
|
||||
|
||||
type Args2 struct {
|
||||
V0 simd.Uint8x32
|
||||
V1 simd.Uint8x32
|
||||
x string
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func simdStructNoSpill(a Args2) simd.Uint8x32 {
|
||||
// amd64:-`VMOVDQU\s.*$`
|
||||
return a.V0.Xor(a.V1)
|
||||
}
|
||||
|
||||
func simdStructWrapperNoSpill(a Args2) simd.Uint8x32 {
|
||||
// amd64:-`VMOVDQU\s.*$`
|
||||
a.x = "test"
|
||||
return simdStructNoSpill(a)
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func simdArrayNoSpill(a [1]Args2) simd.Uint8x32 {
|
||||
// amd64:-`VMOVDQU\s.*$`
|
||||
return a[0].V0.Xor(a[0].V1)
|
||||
}
|
||||
|
||||
func simdArrayWrapperNoSpill(a [1]Args2) simd.Uint8x32 {
|
||||
// amd64:-`VMOVDQU\s.*$`
|
||||
a[0].x = "test"
|
||||
return simdArrayNoSpill(a)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue