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
instructionsunchanged from the scalar versionThe rewrite retires the same number of instructions as before.
IPC2.41Per-cycle progress is high; the core is issuing well.
L1-dcache-load-misses2.8% of loadsMemory access is mostly served by the first-level cache.
branch-misses0.2% of branchesControl flow is predictable.
fp_arith_inst_retired.scalar_single99.7% of FP operationsAlmost every floating-point operation retired is a scalar one.
fp_arith_inst_retired.256b_packed_single0.3% of FP operationsAlmost 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?