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
- call-in-bodyThe loop body calls a function
- extern-call-in-bodyThe loop body calls an external function
- indirect-callThe loop body calls through a function pointer
- alloc-in-bodyThe loop body allocates
- inline-asmThe loop body contains inline assembly
- control-flowThe loop body branches
- early-exitThe loop can leave before its trip count
- int16-elements16-bit integer elements have no kernel