advanced
The Loop That Would Not Widen
Read the counters before the options. Nothing here is labelled with the answer.
The report
We rewrote a numeric kernel expecting a four-times speedup from vectorization. We enabled optimisation, the arrays are contiguous floats, the loop body is one multiply and one add. We got about 4% and cannot work out why the CPU is not using its vector units.
The kernel — caller passes three separately allocated arrays
function scale_add(out, a, b, n, k):
for i in 0 .. n-1:
out[i] = a[i] * k + b[i]
// called as:
scale_add(result, xs, ys, n, 2.5)CountersSIMULATED
| instructions | unchanged from the scalar version | The rewrite retires the same number of instructions as before. |
| IPC | 2.41 | Per-cycle progress is high; the core is issuing well. |
| L1-dcache-load-misses | 2.8% of loads | Memory access is mostly served by the first-level cache. |
| branch-misses | 0.2% of branches | Control flow is predictable. |
| fp_arith_inst_retired.scalar_single | 99.7% of FP operations | Almost every floating-point operation retired is a scalar one. |
| fp_arith_inst_retired.256b_packed_single | 0.3% of FP operations | Almost no wide vector floating-point operations are retired. |
Compiler optimisation report for the loop
scale_add: loop at line 2 not vectorized: cannot prove pointers 'out' and 'a' are independent runtime aliasing check would require 3 comparisons consider annotating parameters as non-aliasing
What is the hardware doing?