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
diff --git a/src/cmd/compile/internal/ssa/rewritetern.go b/src/cmd/compile/internal/ssa/rewritetern.go
index 5493e5f..5c9b889 100644
--- a/src/cmd/compile/internal/ssa/rewritetern.go
+++ b/src/cmd/compile/internal/ssa/rewritetern.go
@@ -174,6 +174,9 @@
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()))
}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
PS6 is ready. Fixed the //go:build tags and changed the code to use _ = instead of fmt.Print
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
More requests, sorry not to catch this on the first time around, and thanks for fixing my bug (I wrote this code, oops). I suspect the trybots will fail again because of build flags and/or lack of an AVX512 check.
//go:build amd64I think you want
```
//go:build goexperiment.simd && amd64
```
and maybe it should be in sim/archsimd/internal/simd_test
where everything is run with the appropriate build flags.
resultsMask := archsimd.Mask64x8{}I'm pretty sure you need to gate this test (and it should fail some trybots)
```
if !archsimd.X86.AVX512() {
t.Skip("Test only applies to AVX512")
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
"Uploaded PS8. Applied the goexperiment.simd tag and the AVX512() check as requested
I think you want
```
//go:build goexperiment.simd && amd64
```
and maybe it should be in sim/archsimd/internal/simd_test
where everything is run with the appropriate build flags.
Done
I'm pretty sure you need to gate this test (and it should fail some trybots)
```
if !archsimd.X86.AVX512() {
t.Skip("Test only applies to AVX512")
}
```
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
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
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi David, thanks for the merge! While working on my project. I noticed we don't seem to have functions for ANDNOT/NOT with masks in simd/archsimd.
I was wondering if there's a specific reason we don't normalize these into a more direct instruction form during the SSA phase, or if it's just a case where the backend is expected to catch it during instruction selection?
I'd love to explore adding a rule for this if you think it's worthwhile.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[release-branch.go1.26] 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 #77773
Change-Id: I0b38312109b9cedaa1cb1320015097d62588a2fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/745460
LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drc...@google.com>
Reviewed-by: Mark Freeman <markf...@google.com>
(cherry picked from commit 8438ace20738cbb1faab5708837e57a50aa774d3)
diff --git a/src/cmd/compile/internal/ssa/issue77582_test.go b/src/cmd/compile/internal/ssa/issue77582_test.go
new file mode 100644
index 0000000..d7bcda6
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/issue77582_test.go
@@ -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{}))
+ }
+}
diff --git a/src/cmd/compile/internal/ssa/rewritetern.go b/src/cmd/compile/internal/ssa/rewritetern.go
index 5493e5f..5c9b889 100644
--- a/src/cmd/compile/internal/ssa/rewritetern.go
+++ b/src/cmd/compile/internal/ssa/rewritetern.go
@@ -174,6 +174,9 @@
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()))
}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
For fixing compiler panic, we usually put tests in GOROOT/test. This should probably be test/simd/issue77582.go
"cmd/compile/internal/archsimd"This package doesn't exist. It should be simd/archsimd.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |