You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: zcse pass does not honor EarlyOk marking #81571
See the last comment on #78997. We sometimes lift an instruction that is arch-gated above the test for the arch gate.
if cpu.HasFeature {
cpu.UseFeature...
}
We can't lift cpu.UseFeature above the if.
This has been solved for the licm (loop invariant code motion) pass, as part of fixing #78997.
It was always solved for cse, as we only common-subexpression eliminate two expressions if one dominates the other. That dominating condition prevents us from moving anything above its feature check.
However, it is not solved for zcse, the zero-argument common-subexpression pass. It lifts things very aggressively to the function entry. I don't think we had any zero-arg gated instructions previously, but now we have some (exactly 1 generic op, I think).
Repro (amd64);
func f() int {
n := 0
if archsimd.X86.AVX512() {
var v archsimd.Int32x16
n += int(v.ReduceSum())
}
if archsimd.X86.AVX512() {
var v archsimd.Int32x16
n += int(v.ReduceSum())
}
return n
}
the arch-independent ZeroSIMD op (which lowers to VMOVDQU64) gets lifted to the start of the function.
With only a single if, that op eventually gets moved by the tighten pass back inside the conditional. It requires 2 ifs to defeat the tighten pass and prevent it from masking the underlying bug.
I think we need to teach zcse to use the EarlyOk flags from #78997, and don't mark ZeroSIMD as EarlyOk.
Activity
gopherbot commentedon Sep 16, 2026
Change https://go.dev/cl/833984 mentions this issue:
cmd/compile: teach zcse to not lift arch-feature-gated instructionsgabyhelp commentedon Sep 16, 2026
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
cmd/compile: teach zcse to not lift arch-feature-gated instructions
gopherbot commentedon Sep 18, 2026
Change https://go.dev/cl/835125 mentions this issue:
cmd/compile: restrict simd test to amd64cmd/compile: restrict simd test to amd64