Mettle

reloaded-baseThe base pointer is re-read every iteration

Reported by --explain after a verdict.

mettle explain reloaded-base

The array the loop indexes is reached through a pointer stored in a struct: t->counts[i] = 0. The body writes through that pointer, and nothing rules out the write landing on the pointer field itself, so the compiler must re-read t->counts on every iteration. A kernel needs one base for the whole loop, so the loop stays scalar.

Fix: read the pointer once into a local and index the local.

var counts: int32* = t->counts;
while (i < n) { counts[i] = 0; i += 1; }

The local says the base does not change, which is what the loop meant. This is a gap in the compiler's alias reasoning, not a fact about your code.

Related