Repository navigation
simd: bridge.LoadFloat32sPart cannot be used in variable initialization #80689
Copy link
Copy link
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
Go version
go version go1.27rc2 darwin/arm64
Output of go env in your module/workspace:
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/rschio/go/bin'
GOCACHE='/Users/rschio/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/rschio/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT='simd'
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/rq/0fx96ptn7w5357fdm_qzflhh0000gn/T/go-build2766455738=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/tmp/report_bug/go.mod'
GOMODCACHE='/Users/rschio/go/pkg/mod'
GONOPROXY='github.com/rschio/*,buf.build/gen/go'
GONOSUMDB='github.com/rschio/*,buf.build/gen/go'
GOOS='darwin'
GOPACKAGESDRIVER=''
GOPATH='/Users/rschio/go'
GOPRIVATE='github.com/rschio/*,buf.build/gen/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/rschio/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27rc2.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/rschio/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='go1.27rc2'
GOTOOLDIR='/Users/rschio/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27rc2.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.27rc2'
GOWORK=''
PKG_CONFIG='pkg-config'What did you do?
I run this program:
package main
import (
"math"
"simd"
)
func main() {
XYToRGB_SIMD(0, 1, 0)
}
// XY represents a XY color in CIE color space.
// This type is adapted to work Philips Hue bulbs color gamut.
type XY struct {
X, Y float32
Bri uint8
}
var (
coeR, _ = simd.LoadFloat32sPart([]float32{1.6564920, -0.354851, -0.255038})
coeG, _ = simd.LoadFloat32sPart([]float32{-0.707196, 1.6553970, 0.0361520})
coeB, _ = simd.LoadFloat32sPart([]float32{0.0517130, -0.121364, 1.0115300})
)
func XYToRGB_SIMD(x, y float32, bri uint8) (uint8, uint8, uint8) {
if y == 0 {
return 0, 0, 0
}
z := 1 - x - y
Y := float32(bri) / 254
X := (Y / y) * x
Z := (Y / y) * z
xyz, _ := simd.LoadFloat32sPart([]float32{X, Y, Z})
var (
rs [3]float32
gs [3]float32
bs [3]float32
)
coeR.Mul(xyz).StorePart(rs[:])
coeG.Mul(xyz).StorePart(gs[:])
coeB.Mul(xyz).StorePart(bs[:])
r := sum(rs[:])
g := sum(gs[:])
b := sum(bs[:])
r = xyToRGBGamma(r)
g = xyToRGBGamma(g)
b = xyToRGBGamma(b)
return to8(r), to8(g), to8(b)
}
func sum(fs []float32) float32 {
var total float32
for _, f := range fs {
total += f
}
return total
}
func xyToRGBGamma(c float32) float32 {
if c <= 0.0031308 {
return 12.92 * c
}
return float32(1.055*math.Pow(float64(c), 1/2.4) - 0.055)
}
func to8(v float32) uint8 {
v = max(v, 0)
v = min(v, 1)
return uint8(v*0xff + 0.5)
}What did you see happen?
I got this output:
report_bug
/Users/rschio/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.27rc2.darwin-arm64/src/simd/internal/bridge/simd_emulated.go:2467:6: internal compiler error: bridge.LoadFloat32sPart (type func([]float32) (bridge.Float32s, int)) and func([]float32) (simd.Float32s, int) are not shape types
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
What did you expect to see?
I expected to see no bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
- StatusShow more project fieldsTodo
Activity
rschio commentedon Aug 2, 2026
I ran in a M3 Pro.
gabyhelp commentedon Aug 3, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
rschio commentedon Aug 3, 2026
Simplified:
magical commentedon Aug 4, 2026
I'm guessing this is a known limitation since the simd package currently has this note:
Edit:
As a workaround, this appears to work:
cagedmantis commentedon Aug 17, 2026
@dr2chase @JunyangShao
philpearl commentedon Aug 28, 2026
I hit the same issue with a simd.Uint8s global variable initialised from simd.BroadcastUint8s(0x80). Moving the initialisation to an init() function also solved my problem
[-]simd: bridge.LoadFloat32sPart ... are not shape types[/-][+]simd: bridge.LoadFloat32sPart cannot be used in variable initialization[/+]spa5k commentedon Sep 20, 2026
Root cause and candidate fix for the ICE
Scope
I confirmed the failure on go1.27.0 darwin/arm64 and on gotip
f043823a. Cross-builds toGOOS=linux GOARCH=amd64andGOOS=js GOARCH=wasmfail in the same way. The emulation copy alone triggers the failure. No vector hardware is needed.-gcflags=-ldoes not change the result.BroadcastUint32sandLoadUint8strigger the failure too. The package-scope initializer is the common factor. One bridge function is not the cause.If the program never reads the variable, the compiler reports a different error. The error is
undefined: bridgeat the initializer. The compiler does not report the ICE:Root cause: the emulation copy shares one syntax node with the original
The midway deep copier builds the emulation copy (
VecLen == 0) with the original name node. TheOnNameExprandOnSelectorbranches put the original node into the new selector:The non-emulation branches build a fresh node with
syntax.NewName. These two branches do not.The failure chain:
types2.Infoin place. It executesc.info.Uses[newName] = oldObj.goto recheckinnoder/irgen.go.bridge.BroadcastUint8s. It writes the bridge object intoinfo.Uses[sharedSel].simd.BroadcastUint8snow resolves to the bridge object. ItsXoperand still sayssimd.TypeAndValueon that node still holds the simd signature. The writer takes the object frominfo.Uses. The writer takes the type from the cache. The two disagree.Writer trace from an instrumented compiler (
-d=simd=2):The first line prints simd text. The syntax supplies the text. But the write uses the bridge object.
info.Usessupplies the object. The reader then buildsxwith the bridge type. The reader takes the reshape target from the simd cache. Neither type carries the shape bit. An instrumented compiler confirms this.HasShape()returns false on both types and on both result types. TheexprReshapeassert inreader.exprfails.Only var initializers fail. The rewriter replaces function bodies with dispatchers. No corrupted original survives. The rewriter keeps var decls verbatim. See
rewrite.go:240-243.Candidate fix
Build a fresh name in both emulation branches:
I verified this fix on gotip
f043823adarwin/arm64. The test compiler contained only this change.Results:
main.init: relocation target simd.BroadcastUint8s not defined.undefined: bridgevariant does not change.init()assignment both build and run.The fix converts the ICE into the documented
BUG(global initialization)failure. A full fix needs one more decision. See the TODO atrewrite.go:242: drop the kept declaration, or neutralize its initializer. I leave this decision to you. I can send a CL for thedeepcopy.gopart on request.gopherbot commentedon Sep 29, 2026
Change https://go.dev/cl/841367 mentions this issue:
cmd/compile: fix midway ICE on shared emulation selector nodecmd/compile: fix midway ICE on shared emulation selector node
dr2chase commentedon Oct 1, 2026
Candidate CL for fixing this, straight LLM output so I still need to review it myself but it handles #81845 (@mauri870) and it did not crash compiling the test for this bug either. https://go.dev/cl/843307
I'd love to hear if it works more generally, or doesn't.
Fixes for the other simd-ast-rewriting bugs recently landed, as well as a few more mask-related operations (not iterators, those are still being discussed).
There are some performance glitches that may take a little longer to land, we want to be sure that we have the
simdAPI in good shape and SVE in good shape, and maybe SVE-support enabled insimd.spa5k commentedon Oct 1, 2026
I tested CL 843307 with three cases.
So the CL fixes the init cases. It does not fix #81614. That is a separate bug.
Built patchset 1 on master 6bbd163, GOEXPERIMENT=simd, darwin/arm64.
EDIT: More testing, still patchset 1: