cmd/compile: avoid panic in ternary rewrite on checked instructions

The replace function in rewritetern.go was panicing when encountering
instructions that had already been processed. This adds a check to
ensure we don't trigger a panic on these instructions.

Fixes #77582

Change-Id: I0b38312109b9cedaa1cb1320015097d62588a2fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/745460
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
This commit is contained in:
Eyalcfish
2026-02-13 21:44:32 +02:00
committed by David Chase
parent c2fabf1a26
commit 8438ace207
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
// Copyright 2026 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.
//go:build goexperiment.simd && amd64
package ssa
import (
"testing"
"cmd/compile/internal/archsimd"
)
func TestVPTERNLOGDPanic(t *testing.T) {
if !archsimd.X86.AVX512() {
t.Skip("Test only applies to AVX512")
}
resultsMask := archsimd.Mask64x8{}
a := archsimd.Mask64x8FromBits(0xFF)
b := archsimd.Float64x8{}.Less(archsimd.Float64x8{})
for i := 0; i < 1; i++ {
resultsMask = a.Or(b).Or(resultsMask)
// This nested logic triggered the panic
_ = resultsMask.And(resultsMask.And(archsimd.Mask64x8{}))
}
}

View File

@@ -174,6 +174,9 @@ func rewriteTern(f *Func) {
replace := func(a0 *Value, vars0 [3]*Value) {
imm := computeTT(a0, vars0)
op := ternOpForLogical(a0.Op)
if a0.Op >= OpAMD64LoweredGetClosurePtr {
return // It is already an AMD64 machine instruction
}
if op == a0.Op {
panic(fmt.Errorf("should have mapped away from input op, a0 is %s", a0.LongString()))
}