Mettle

variable-shiftA shift by a distance read at run time

Reported by --explain after a verdict.

mettle explain variable-shift

The kernels carry a shift only when the distance is written in the source. A distance the loop reads has no kernel, in either direction:

b[i] = a[i] >> k;      // `k` a parameter or a variable
b[i] = a[i] << k;

Both stay scalar. A constant distance vectorizes:

b[i] = a[i] >> 8;

There is no source rewrite that reaches a kernel while the distance stays a run-time value, so this is a gap in the compiler rather than a problem with the loop. Splitting into one loop per distance works when the distances are few and known.

Related