CONCEPT Cited by 1 source
Auto-vectorization¶
Definition¶
Auto-vectorization is a compiler optimization where the compiler transforms scalar loop code into SIMD (Single Instruction, Multiple Data) instructions without explicit programmer annotations. The compiler pattern-matches loop bodies and emits vector instructions that process multiple data elements per instruction (e.g., 16 bytes at a time with 128-bit NEON, 32 with AVX2, 64 with AVX-512).
Preconditions¶
Auto-vectorization requires that the loop body:
- Has no data-dependent control flow — no
break, no conditional early-exit, no branches whose outcome depends on the data being processed. This is the single most critical requirement. - Performs uniform operations — the same operation on every element.
- Has no loop-carried dependencies — each iteration is independent of the previous one.
- Accesses contiguous memory — scatter/gather patterns may partially vectorize but at reduced efficiency.
The early-exit barrier (canonical example)¶
GitHub's casefold crate demonstrates that a single data-dependent break is sufficient to completely prevent vectorization, even if the loop body is otherwise perfectly branchless:
- Branchless body +
breakon non-ASCII: 0 vector instructions, 2.6 GiB/s - Branchless body + no break (OR-accumulator): 41 vector instructions, >45 GiB/s
The compiler cannot vectorize across a data-dependent loop exit because it would need to speculatively process elements past the exit point and then discard the results — fundamentally incompatible with SIMD's operate-on-a-whole-register model.
(Source: sources/2026-07-31-github-dont-stop-early-case-folding-source-code-at-memory-speed)
Partially vectorized state¶
Between "no vectorization" and "fully vectorized" there's a middle ground: LLVM may vectorize parts of the loop body while leaving others scalar. GitHub measured this intermediate state at 7.6 GiB/s (25 vector instructions) — when the break was removed but the body still contained a conditional write (compare-blend-masked-store). Making the write unconditional via arithmetic moved to full vectorization (41 vector instructions, >45 GiB/s).
Seen in¶
- sources/2026-07-31-github-dont-stop-early-case-folding-source-code-at-memory-speed — canonical wiki instance; LLVM auto-vectorization of Rust code to NEON 16-byte instructions
- sources/2026-03-03-netflix-optimizing-recommendation-systems-with-jdks-vector-api — explicit vectorization via JDK Vector API (complementary approach when auto-vectorization fails)
Related¶
- concepts/branchless-programming — the code style that enables auto-vectorization
- concepts/simd-vectorization — the hardware instructions auto-vectorization targets
- patterns/branchless-sweep-then-check — design pattern for vectorization-friendly loops