Repository navigation
Conversation
… capture
The rewritten code adds names that begin with an underscore (_i,
_count, _w1, broadcast vectors declared before the loop, ...) and relies
on predeclared names (len, min, max, copy, uint64, the element types) and
on the simd and unsafe packages. Each can mean something else in the
function, and then the vector loop silently computes something else.
All of these already go wrong on master:
func F(dst, a []int32, _i int) { for i := 0; i < _i; i++ { ... } }
reads loopvec's _i in the loop condition and never runs; with a
package-level func len(s []int32) int the vector loop takes its window
length from that len; and a reduction written as for n := range n, or
for n := n - 1; n >= 0; n--, finishes with for n := _i; n < n; n++,
which never runs.
A loop that would otherwise be rewritten is now left alone, each with
its own reason, when its function uses an identifier that begins with an
underscore, other than _; when one of the names the code relies on,
looked up from the loop, is declared again around it, in the package, or
by an import; or when the loop declares such a name itself, or a name
its range operand or initial values use. The names the overlap helper
uses (uintptr, int, bool, any, false) are checked at package level,
where loopvec declares it. The lookup needs scopes, so the toolexec
wrapper records them. No loop in std, gonum or
github.com/thesyncim/goav1 stops being vectorized.
fixBlankParams works around a compiler bug that rejects _ parameters in
functions with simd code by renaming them _p0, _p1, ..., but it renamed
them in every function of a rewritten file. In a function that reads a
package-level _p0, the parameter then hid it:
var _p0 = 5
func Offset(_ int) int { return _p0 }
became func Offset(_p0 int) int { return _p0 } and returned its
argument. Only the functions loopvec rewrote are renamed now. They
mention no name that begins with an underscore, so the new names cannot
capture anything.
The runners have moved to ubuntu-26.04, so this is the qemu part of #1 you said you'd take when that happened. `qemu-user-static` has no installation candidate there, so every PR now fails at that step and the arm64 runs, the golden check, fmt and lint get skipped. You can see it on #7, #9 and #19, where Build, Test and the amd64 tsvc run all pass first. master's last run predates the move, so the next push will hit it too. `qemu-user` has the static emulators on 26.04, just without the `-static` names, so this installs that and links `qemu-aarch64-static` when it's missing, since the Makefile runs that name. It's been passing on my fork's ubuntu-26.04 runners, and this PR's own CI runs it too.
|
Thanks, this is a real fix: each case in the description computes the wrong result silently on master. I checked that the two name lists cover everything the emitter writes. That's Two things to change:
Nits, take them or leave them:
|
The rewritten code adds names that start with an underscore, some of them declared before or inside the loop. It also calls
len,min,maxandcopy, converts withuint64and the element types, and refers to the packagessimdandunsafe. The function, its package or an import can give any of those names another meaning, and then the vector loop silently computes something else. These all go wrong on master:The vector loop's condition reads loopvec's
_iinstead of the parameter, so it never runs. In a package that declaresfunc len(s []int32) int { return cap(s) / 4 }, the vector loop takes its length from thatlenand stops a quarter of the way. And a sum written asfor n := range n { s += a[n] }, or asfor n := n - 1; n >= 0; n--, finishes its last elements withfor n := _i; n < n; n++, which never runs, so the result is short.A loop that would otherwise be rewritten is now left alone, with its own reason, when:
_. Rather than track which names each part of the emitter uses, this covers the names loopvec adds now and any it adds later;maxdeclared after the loop doesn't count. The overlap helper's own names (uintptr,int,bool,any,false) are checked at package level, where it is declared. The toolexec wrapper now records scopes for this;for n := range n,for n := n - 1; ...,for len := range a).These checks run last, so a loop that can't be vectorized anyway keeps the reason that matters.
The second commit fixes the same kind of bug in
fixBlankParams. It renames_parameters to_p0,_p1, ... to work around a compiler bug with simd code, but it did that in every function of a rewritten file, sofunc Offset(_ int) int { return _p0 }started returning its argument instead of a package-level_p0. Now it only renames in the functions loopvec rewrote, which can't mention such names.No loop in std, gonum or goav1 stops being vectorized.
reserved_names.txtandblank_params.txtcover each case. A rewrite that doesn't type-check still falls back in toolexec;toolexec_falls_back_when_rewrite_does_not_compile.txtused a parameter namedsimdto get one, which is now rejected earlier, so it uses a package that declares_loopvecOverlapitself instead.This is #3 again, now that #2 is in.