Repository navigation
cmd/compile: internal compiler error: panic during rewrite tern with GOEXPERIMENT=simd #77582
Description
ENVIORMENT: zorin os on Inspiron-5406-2n1, go version go1.26rc3 linux/amd64, ive recently tried to transfer my shooting simulation for my FRC team project from normal calculate to SIMD based calculations(for performance), after trying for a while ive encountered a bug where the compiler crashes if a instruction is done with any combination of avx512, now i have absolutly no idea why this combination of lines causes this error:
resultsMask := archsimd.Mask64x8{}
for {
resultsMask = archsimd.Mask64x8FromBits(0).Or(archsimd.Float64x8{}.Less(archsimd.BroadcastFloat64x8(0))).Or(resultsMask)
fmt.Print(resultsMask.And(resultsMask.And(archsimd.Mask64x8{})))
}
causes :
GOEXPERIMENT=simd go build main.go
command-line-arguments
./main.go:192:2: internal compiler error: 'main': panic during rewrite tern while compiling main:
should have mapped away from input op, a0 is v100 = ternInt32x16 [254] v146 v96 v42 (resultsMask[archsimd.Mask64x8])
goroutine 9 [running]:
cmd/compile/internal/ssa.Compile.func1()
cmd/compile/internal/ssa/compile.go:49 +0x67
panic({0xfb60e0?, 0x28bdaed1eda0?})
runtime/panic.go:860 +0x13a
cmd/compile/internal/ssa.rewriteTern.func4(0x28bdaeba3b90, {0x28bdaeba4fb0, 0x28bdaeba39d0, 0x28bdaeba2230})
cmd/compile/internal/ssa/rewritetern.go:178 +0x2f3
cmd/compile/internal/ssa.rewriteTern.func6(0x28bdaeba3ce0)
cmd/compile/internal/ssa/rewritetern.go:239 +0x644
cmd/compile/internal/ssa.rewriteTern(0x28bdae5bc1c0)
cmd/compile/internal/ssa/rewritetern.go:290 +0x5e4
cmd/compile/internal/ssa.Compile(0x28bdae5bc1c0)
cmd/compile/internal/ssa/compile.go:97 +0xbd9
cmd/compile/internal/ssagen.buildssa(0x28bdae3cb540, 0x7, 0x0)
cmd/compile/internal/ssagen/ssa.go:594 +0x2de5
cmd/compile/internal/ssagen.Compile(0x28bdae3cb540, 0x7, 0x10c2af8?)
cmd/compile/internal/ssagen/pgen.go:304 +0x88
cmd/compile/internal/gc.compileFunctions.func5.1(0x466cb0?)
cmd/compile/internal/gc/compile.go:199 +0x38
cmd/compile/internal/gc.compileFunctions.func3.1()
cmd/compile/internal/gc/compile.go:181 +0x30
created by cmd/compile/internal/gc.compileFunctions.func3 in goroutine 8
cmd/compile/internal/gc/compile.go:180 +0x325
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
gabyhelp commentedon Feb 13, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
JunyangShao commentedon Feb 13, 2026
This pass is doing a rewrite of a tree of SIMD logical expressions to use the VPTERNLOGD instruction.
I think we have a bug
@golang/compiler
@dr2chase
gopherbot commentedon Feb 13, 2026
Change https://go.dev/cl/745460 mentions this issue:
cmd/compile: avoid panic in ternary rewrite on checked instructionsdr2chase commentedon Feb 24, 2026
@gopherbot please open a backport issue to 1.26.
This is not a regression because it is a new feature (and an experiment), but we want people to try it out.
gopherbot commentedon Feb 24, 2026
Backport issue(s) opened: #77773 (for 1.26).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.
cmd/compile: avoid panic in ternary rewrite on checked instructions
gopherbot commentedon Feb 25, 2026
Change https://go.dev/cl/748760 mentions this issue:
test/simd: add test for issue 77582test/simd: add test for issue 77582
gopherbot commentedon Feb 25, 2026
Change https://go.dev/cl/749241 mentions this issue:
cmd/compile: ternary rewrite of rewrite should skip, not panicEyalcfish commentedon Feb 26, 2026
I have found that the bug is caused because of a value being used as the argument for 2 separate values, so when the rewrite function rewrites it once to use VPTERNLOGD and then again, the second time a panic occurs(because it just doesnt change anything), i am wondering if we could disable this by just removing the panic check: if op == a0.Op { panic ... or skipping the replace if its already a VPTERNLOGD instruction or there isn't supposed to be a value being used as the argument for 2 values in the first place?
Eyalcfish commentedon Feb 26, 2026
I also found that adding boolExprTrees[a0] &= sloInterior at the end of the replace function works, And I think its more elegant than the other solutions
cherrymui commentedon Feb 26, 2026
Reopen. CL 745460 reverted.
The new fix is CL 749241.
cmd/compile: ternary rewrite of rewrite should skip, not panic