Skip to content

cmd/compile: internal compiler error: panic during rewrite tern with GOEXPERIMENT=simd #77582

Closed

Description

@Eyalcfish

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

Activity

  1. added
    BugReportIssues describing a possible bug in the Go implementation.
    on Feb 13, 2026
  2. JunyangShao commented on Feb 13, 2026

    @JunyangShao
    Contributor

    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

  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Feb 13, 2026
  4. gopherbot commented on Feb 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/745460 mentions this issue: cmd/compile: avoid panic in ternary rewrite on checked instructions

  5. dr2chase commented on Feb 24, 2026

    @dr2chase
    Contributor

    @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.

  6. gopherbot commented on Feb 24, 2026

    @gopherbot
    Contributor

    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.

  7. added a commit that references this issue on Feb 24, 2026
    8438ace
  8. gopherbot commented on Feb 25, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/748760 mentions this issue: test/simd: add test for issue 77582

  9. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Feb 25, 2026
  10. added this to the Go1.27 milestone on Feb 25, 2026
  11. added a commit that references this issue on Feb 25, 2026
  12. gopherbot commented on Feb 25, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/749241 mentions this issue: cmd/compile: ternary rewrite of rewrite should skip, not panic

  13. Eyalcfish commented on Feb 26, 2026

    @Eyalcfish
    ContributorAuthor

    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?

  14. Eyalcfish commented on Feb 26, 2026

    @Eyalcfish
    ContributorAuthor

    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

  15. cherrymui commented on Feb 26, 2026

    @cherrymui
    Member

    Reopen. CL 745460 reverted.
    The new fix is CL 749241.

  16. added a commit that references this issue on Feb 26, 2026
    89d92fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions