Early Exit Kills the Vectorizer. GCC 14's New Early-Break Support Doesn't Save You.
Published: October 29, 2026 | Benchmarking & Profiling Networking & Market Data SIMD & Vectorization
Early Exit Kills the Vectorizer. GCC 14's New Early-Break Support Doesn't Save You.
Two loops. Same buffer, same task: lowercase every ASCII byte in place, tell me where the first non-ASCII byte is. The first one is what everybody writes:
size_t fold_naive(uint8_t* p, size_t n) {
for (size_t i = 0; i < n; ++i) {
uint8_t b = p[i];
if (b >= 0x80) return i; // non-ASCII: stop, hand off
if (b >= 'A' && b <= 'Z') p[i] = b + 32;
}
return n;
}
On aorus (Threadripper 3960X, Zen 2, isolated core, g++-14 -O3 -march=native) this runs at 1.97 GiB/s on a 5.7 KB ASCII buffer. The second loop deletes the break, accumulates the "did I see a high bit" answer in an OR, and turns the conditional store into arithmetic:
size_t fold_sweep(uint8_t* p, size_t n) {
uint8_t acc = 0;
for (size_t i = 0; i < n; ++i) {
uint8_t b = p[i];
acc |= b; // any non-ASCII? check later
uint8_t is_upper = uint8_t(b - 'A') < 26;
p[i] = b | uint8_t(is_upper << 5); // lowercase, or no-op
}
return (acc & 0x80) ? first_non_ascii(p, n) : n;
}
Same compiler, same flags, same buffer: 51.7 GiB/s. That is 26x, and the only semantic difference is that the second loop does more work: it touches every byte even when a non-ASCII byte sits at position three, then goes back to find it. IQR under 3% on both cells, verify gate bit-identical against a scalar reference before any timing was recorded.
The claim under test comes from GitHub engineering's "Don't stop early: case-folding source code at memory speed" (Neubeck and Orzell, July 2026), the writeup behind their casefold Rust crate. Their headline table, measured on an Apple M4: naive 3.1 GiB/s, branchless body with the break kept 2.6, break dropped 7.6, fully branchless above 45. Their mechanism claim is that a data-dependent loop exit by itself suppresses LLVM's vectorizer, no matter how clean the body is. They also warn, correctly, that none of these numbers are portable across microarchitectures. So we ported the experiment to C++ and ran it on the machine this Substack actually publishes numbers from, across four compilers. Parts of their story reproduce almost exactly. One rung of their ladder turns out to not exist on AVX2 at all, and to be the fastest loop of the four on an AVX-512 core. And then our own challenge leaderboard has something to say about whether any of this matters when real money-adjacent code is on the line.
The ladder is really a 2x2 matrix
GitHub presents four versions as a cumulative ladder. Structurally they are a 2x2: one axis is the early exit (keep the break or sweep everything with an OR-accumulator), the other is the store (branchy if (is_upper) store or unconditional masked write). Measured at their 5.7 KB buffer size:
| loop | gcc-13 | gcc-14 | clang-18 | clang-20 |
|---|---|---|---|---|
| early exit + branchy store (naive) | 1.98 | 1.97 | 1.32 | 1.32 |
| early exit + branchless body | 1.47 | 1.47 | 1.32 | 1.47 |
| no exit + branchy store | 1.98 | 1.97 | 2.27 | 2.25 |
| no exit + branchless body (sweep) | 47.6 | 51.7 | 50.1 | 49.9 |
GiB/s, median of 11 samples, IQR < 3% on every cell.

Read the table by columns and the M4 story survives: the only loop that runs at memory-system speed is the one with no exit and no branch in the body, and the gap to everything else is a factor of 22 to 38 depending on compiler and on which scalar row you measure against. The vector-instruction counts from objdump agree: both early-exit rows compile to zero vector instructions on all four compilers. The exit is the cliff. Zen 2 makes the cliff steeper than the M4's 15x, mostly because the scalar loops are slower here while the AVX2 sweep is faster than their NEON one.
Read the table by rows, though, and two things diverge from the Rust-on-M4 version.
The 7.6 GiB/s middle rung does not exist on AVX2
On the M4, dropping the break while keeping the conditional store got GitHub 7.6 GiB/s: LLVM partially vectorized, compiling the conditional store to a compare-blend-masked-store. That rung is the reason their ladder feels gradual. On Zen 2 that row runs at 2.0-2.3 GiB/s: scalar speed plus rounding error.
The disassembly explains it, and the two compilers fail in opposite ways. GCC looks at the conditional store and declines to vectorize the loop at all: 50 instructions, all scalar. Clang "vectorizes" it: 1,369 instructions in the function, 557 of them touching ymm registers, and it still runs within 15% of GCC's scalar version. What clang emits is a vector load and compare followed by 32 scalar lanes of test-branch-store, one per byte. The reason it cannot do what the M4 build did is not vectorizer quality, it is the ISA and the language in combination: AVX2 has no byte-granular masked store (vpmaskmov starts at dword granularity), and rewriting the conditional store as an unconditional "store the blend of old and new" is a transform the C++ memory model forbids, because inventing a store to a byte the source program never wrote is a data race if another thread happens to own that byte (the C++11 memory model rules out compiler-invented stores; Boehm's C++ memory model pages collect the history, and the PLDI 2008 Boehm-Adve paper is the primary source).
Ask the compilers and they will tell you all of this, which I did not expect and which changes how you should hunt for these loops. Compile with -Rpass=loop-vectorize -Rpass-missed=loop-vectorize on clang and -fopt-info-vec -fopt-info-vec-missed on GCC, both at -march=znver2, and the four ladder rows report:
clang-20 V1 break + branchy Cannot vectorize early exit loop
clang-20 V2 break + branchless Cannot vectorize early exit loop with writes
to memory
clang-20 V3 nobreak + branchy vectorized loop (width: 32, interleaved: 4)
clang-20 V4 sweep vectorized loop (width: 32, interleaved: 4)
g++-14 V1 break + branchy not vectorized: unsupported control flow
g++-14 V2 break + branchless can't safely apply code motion to
dependencies of b_13 = *_1
g++-14 V3 nobreak + branchy not vectorized: unsupported control flow
g++-14 V4 sweep loop vectorized using 32 byte vectors
Nothing here is silent. Both early-exit rows get a named reason from every compiler on the rig, and clang-20's reason is specific enough to grep for in a build log, which clang-18 was not: on 18 the same two loops report only "could not determine number of loop iterations". GCC 14 names the store directly in V2, which is the early-break support telling you it cannot hoist a write past the exit.
Then look at V3 and V4 on clang. Same remark, word for word, width 32, interleave 4, for two loops that measure 2.25 and 49.9 GiB/s. The remark reports that the vectorizer ran and emitted something. Whether what it emitted is vector code you want is a separate question, and V3's "vectorized" body is the 32-lane test-branch-store from the paragraph above. If you are using the vectorizer report as a green light, that row is where it lies to you, and the instruction census does not save you either, because 557 ymm instructions look like success too. The thing that catches it is the clock.
That last point about the memory model is worth sitting with, because it is the part everybody gets backwards. The unconditional store in fold_sweep is not an optimization the compiler found. It is a license you grant in source code. Once you write the store unconditionally, blending it into a 32-byte vector write is trivially legal and the whole loop collapses to straight-line SIMD. Keep the if, and no conforming compiler on this ISA is allowed to build the fast version for you, no matter how smart its cost model gets.
On AVX-512 the middle rung is the fastest loop
That argument stops at AVX2's edge. AVX-512BW has the byte-granular masked store AVX2 lacks, vmovdqu8 under a mask register, and a masked store writes only the bytes whose mask bit is set, so it invents no store and the memory-model objection does not apply. I built the same kernels twice on the Zen 5 laptop (Ryzen AI 7 PRO 350, taskset -c 4, no isolation), once at -march=znver5 and once with -mno-avx512f added, so the core stays the same and only the instruction set changes. Both compilers vectorize the middle rung at AVX-512 width: a byte compare into a mask, a skip when none of the 64 bytes needs folding, and a masked store. Every build passed the verify gate first.
| loop | gcc-14 AVX-512 | gcc-14 AVX2 | clang-20 AVX-512 | clang-20 AVX2 |
|---|---|---|---|---|
| middle rung, clean buffer | 101 | 4.0 | 102 | 7.4 |
| middle rung, half the bytes fold | 97 | 0.32 | 140 | 0.25 |
| sweep, clean buffer | 91 | 71 | 87 | 82 |
| sweep, half the bytes fold | 70 | 74 | 117 | 93 |
| naive early exit, clean buffer | 2.7 | 2.5 | 4.1 | 4.0 |
GiB/s, median of 11 samples, IQR over median at most 2.0% in every cell. The clean buffer is the already-folded 5.7 KB one from the matrix above.
The laptop is not isolated and for this table it does not need to be: the smallest effect read from it, the middle rung over the sweep at AVX-512 width, is 11 to 39%, against a spread of at most 2%. At AVX2 width the middle rung is the scalar-speed loop from the section above, and it walks off the store-selectivity cliff like every branchy store, from 4 GiB/s down to a third of one. At AVX-512 width it is the fastest loop in the table and does not care how many bytes fold. Why it beats the sweep I did not measure. My guess is that the masked store leaves untouched bytes alone and the block skip leaves whole 64-byte groups alone, where the sweep writes every byte, but no counter was taken.
So the rule about the store belongs to the instruction set rather than to the language. On AVX2 a conditional byte store keeps the loop scalar and the unconditional store is the license the vectorizer needs. On an AVX-512 core the same source vectorizes as written, and the if is the faster way to write it. The exit is a different story: on Zen 5 the naive loop is still scalar at 2.5 to 4.1 GiB/s on both compilers.
GCC 14's early-break vectorizer does not save you either
GCC 14 shipped support for vectorizing loops with early exits, work driven mostly by Arm. Before running anything we wrote the prediction down, and marked it a hit afterwards: that it would not fire here, because the fold stores to the buffer before the exit, and the early-break support cannot yet speculate past a store whose execution depends on lanes after the exit point. That is exactly what happens: gcc-14 emits zero vector instructions for both early-exit variants, same as gcc-13, same as both clangs. The GitHub claim was made about LLVM; it survives GCC 14's newest vectorizer too. If your scan loop writes as it goes and can bail out mid-buffer, none of the four compilers on this rig will vectorize it for you.
GCC 16 vectorizes the branchless early exit
The early-exit half of that has already started to date. GCC 16's release notes say the vectorizer "now supports vectorizing uncounted loops or loops for which the number of iterations could not be determined", and LLVM's documentation now lists early-exit vectorization, so both early-exit folds went back to aorus core 18 under GCC 16.1.1 and a Clang 22 snapshot (a 22.0.0git build of a fork of LLVM rather than a release). The Clang snapshot emits no vector instruction for either fold, or for the read-only sentinel loop. GCC 16 vectorizes the branchless one and says so, optimized: loop vectorized using 32 byte vectors and unroll factor 32:
| buffer | gcc-14, early exit | gcc-16, early exit | gcc-16, sweep |
|---|---|---|---|
| 256 B | 1.40 | 8.03 | 27.6 |
| 1 KiB | 1.44 | 37.9 | 42.6 |
| 5.7 KB | 1.45 | 34.9 | 46.9 |
| 64 KiB | 1.45 | 44.0 | 44.0 |
| 1 MiB | 1.44 | 41.8 | 42.2 |
| 32 MiB | 1.45 | 12.3 | 12.4 |
GiB/s, median of 11 samples, isolated core 18, worst IQR 0.6%.
From 64 KiB up GCC 16's early-exit loop runs as fast as the sweep, and unlike the sweep it can stop. Below that it is slower, 3.4 times at 256 bytes, and I have no story for that yet. The naive loop, the one with the conditional store, is still scalar under GCC 16 at 1.96 GiB/s, and so is the middle rung at AVX2 width. So the advice below survives GCC 16 for the loop most people write, and for anything that also has to build under Clang. For a branchless early exit on GCC 16 it turns into a question of buffer size, which means asking for the remark and then timing the loop.
Branchless scalar code: the M4's pessimization does not reproduce here
The M4 post's cutest result was that making the body branchless while keeping the break made the loop slower (2.6 vs 3.1): the branchy store skips the write for every byte that does not fold, the branchless one writes all of them, and without vectorization the extra stores are pure cost. On GCC the ordering repeats, 1.47 against 1.98, but that gap sits inside the layout band this rig shows for scalar cells (the methodology note at the end has the same loops moving by up to 50% between rebuilds), so I am not counting it as a reproduction. On clang both variants land at 1.3-1.5 and which one wins flips between rebuilds, which is our first sighting of a theme: at scalar speeds, loop-body codegen details and code layout move numbers by more than the effect you are measuring. More on that in the methodology note.
Where the branchy store genuinely earns its keep, and then loses it, is selectivity. The 0% column above is the friendly case: nothing folds, the store branch never fires, the predictor is perfect. Crank up the fraction of bytes that need the store and the naive loop walks off the same cliff every branchy filter walks off:

At 1 MiB, single-pass timing on g++-14: the branchy loop does 1.98 GiB/s at 0% uppercase, 1.70 at 1%, 0.80 at 10%, 0.28 at 50%. Sevenfold collapse, textbook store-branch misprediction, and the same curve we measured from the other side in our cmov-vs-branch article. The branchless body sits at 1.47 regardless, so it overtakes the branchy one somewhere between 1% and 10%: the grid was 0/1/10/25/50 and it does not resolve the crossing any tighter than that. Interpolating time per byte puts it near 2%, and I would not defend the second digit. On clang the question does not arise, because its branchless body is already level with its branchy one at 0% selectivity, both at 1.318. The sweep does 56 GiB/s and does not care. If you know your store fires less than one time in fifty and you are pinned to scalar code for other reasons, the branch is defensible. Otherwise this entire trade-off is an argument between two loops that are both 25x off the pace.
When stopping early actually pays
The whole point of an early exit is that sometimes it exits early. Fair. So where is the break-even? We planted a single non-ASCII byte at a controlled position in a 1 MiB buffer and timed the naive stop-at-it strategy against the sweep-everything-then-locate strategy, as a function of where the byte lands:

The arithmetic was always going to win this argument: the scalar stopper covers bytes at 1.98 GiB/s, the sweep covers all of them at 44.6, so stopping pays only while the exit lands within 1.98/44.6 of the buffer, which is 4.4%. Clang, with its slower scalar loop, crosses at 3.1%. In other words: unless you expect the thing you are scanning for inside the first one-twentieth of the buffer, the "optimization" of bailing out early is costing you the whole vector unit. For protocol work the practical reading is even more lopsided, because the garbage byte you are guarding against essentially never arrives, and every clean message pays the scalar tax for the exit you almost never take.
One honest wrinkle from the same figure: the sweep's own cost is not perfectly flat, because after the OR-accumulator trips it still has to walk the buffer to locate the first offending byte. With the bad byte at 50% that locate pass drags the sweep from 44.6 down to 21.6 GiB/s. Still 5x ahead of stopping.
Does it survive at 160 bytes?
Everything above is 5.7 KB and 1 MiB buffers, and the obvious HFT objection is that a FIX message is a few hundred bytes, where vector prologue overhead supposedly eats the win. Measured, that objection does not hold:

At 256 bytes the sweep still runs 28.8 GiB/s on g++-14, against that compiler's naive loop at 1.89: a factor of 15. Clang is the more flattering column and the one I first wrote down, 28.8 against 1.28 for a factor of 22, but its scalar loop is slower rather than its vector loop faster, so 15x is the honest number for the compiler this article headlines. The vectorized loop does give up 37 to 44% of its peak at that size depending on compiler (prologue and call overhead amortized over too few iterations), and 60% of 50 GiB/s is still a different universe from 1.3. At the other end, 32 MiB spills to DRAM and compresses everything. Take one compiler at a time: g++-14's sweep drops to 12.8 and its two-pass to 7.0, a 6.5x ratio over its naive loop; clang-20's sweep drops to 13.5 and its two-pass to 6.9, a 10x ratio. The two-pass variant reads everything twice, and past L3 that finally costs close to the full 2x. Between those extremes, from L1 to L3, the win is 19 to 38x. There is no buffer size at which the early exit is the right call on this machine, other than the case from the crossover plot where the exit fires almost immediately.
The two-pass and fused variants deserve one paragraph, because the M4 post made a memorable claim there: their chunked check-then-convert fused loop was 2.6x slower than doing two clean passes, "the branch is the enemy" one more time. On Zen 2 that reproduces only on clang (11.7 vs 21.7 at 1 MiB, a 1.9x penalty). GCC lands within a few percent either way: 19.1 fused against 18.2 two-pass on gcc-14 at 1 MiB, and 20.8 against 21.3 on gcc-13, where the two-pass is the one in front. At 5.7 KB gcc-13's two-pass pulls further ahead, 22.5 against 20.1. The fused-versus-two-pass question, unlike the early-exit question, has a compiler-dependent answer, and if you care you have to measure your own toolchain. The early-exit cliff is the portable part.
The FIX parser test, and what the leaderboard already knew
Scanning ASCII for delimiters while validating the payload is not a toy: it is the shape of every FIX tokenizer's hot loop. SOH (0x01) separates fields, and outside the binary-carrying fields anything below 0x20 or above 0x7e means the feed handed you garbage. (FIX does carry binary: RawData, tag 96, holds arbitrary bytes with its length in tag 95, so a tokenizer that validates every byte the same way has to special-case it. The batch generated here has no RawData field.) The usual instinct is the naive loop above: walk bytes, record delimiter offsets, bail the moment something looks wrong. We built three tokenizers with the same contract (offsets of every SOH, reject on any invalid byte, output verified bit-identical across all three plus garbage-injection tests) and ran them over a 4 MiB batch of realistic FIX 4.4 messages averaging 160 bytes.
The byte-walking early-exit tokenizer: 1.6-2.2 GiB/s depending on compiler, 67 to 96 ns per message. The branch-free version, validity as an OR-reduction plus a SWAR zero-byte trick to find SOH bytes eight at a time: 3.7-4.2 GiB/s. Rewriting that with AVX2 intrinsics (vpcmpeqb + vpmovmskb, validity folded into the same pass) reaches 5.1-7.4 GiB/s, 20 to 29 ns per message, with the two clangs at the top of that range and gcc-13 at the bottom.
Where the rest of the time goes was inferred in the first run and measured in a later one, on the same isolated core: each tokenizer timed as written, and again with the drain replaced by a popcount that counts the delimiters and extracts nothing. Every variant returns the same delimiter count, and the as-written cells land within 3% of the numbers above.
| tokenizer | as written | popcount only | the drain's share |
|---|---|---|---|
| AVX2, g++-14 | 5.22 | 46.20 | 89% |
| AVX2, clang-20 | 7.26 | 41.25 | 82% |
| SWAR, g++-14 | 3.70 | 7.97 | 54% |
| SWAR, clang-20 | 4.11 | 4.80 | 14% |
GiB/s, median of 11 samples, worst IQR 0.54%.
For the AVX2 tokenizer the drain is most of the time, 82 to 89% of it: popping delimiter offsets out of the mask bits one ctz at a time, at one delimiter every 9.4 bytes. For the SWAR one the answer depends on the compiler, half the time on GCC and a seventh on clang, whose SWAR scan is slow enough by itself (4.8 GiB/s with nothing to drain) that the extraction barely shows. The locked prediction guessed 8-20 GiB/s for the SWAR version and missed by 2 to 5x. Without the drain, GCC's scan lands at 8.0, the bottom of that range, and clang's at 4.8, below it: on one compiler the prediction forgot the extraction, on the other it overrated the scan. Vectorizing the looking is easy; vectorizing the reporting is the actual problem.
Which raises the question a reader asked while this experiment was running: toy kernels are nice, but how does any of this compare against code written by people competing for rank? Challenge 09 on hftuniversity.com is a full FIX parser: extract seven fields, parse timestamps to nanoseconds, convert prices to fixed-point, validate checksums, on the same message shape. We took four best-per-user submissions off the leaderboard, spanning the score range, rebuilt them from source, and ran them on the same isolated core with the challenge's own harness. Anonymized, as always for platform code:
| tier | cycles/KB (aorus, 1 core) | as GiB/s at 3.8 GHz TSC |
|---|---|---|
| Solution A (top of board) | 352 | 10.3 |
| Solution B (gold badge) | 642 | 5.6 |
| Solution C (bronze badge) | 1069 | 3.4 |
| Solution D (unbadged) | 3582 | 1.0 |

Two observations, and they are the reason this section exists. First: we read all four solutions, and nobody on the board stops early. Not one ranked submission walks bytes with a bail-out branch in the hot loop; every tier from bronze up sweeps buffers with branch-free AVX2, exactly the pattern this article has been measuring, and even the unbadged solution at 1.0 GiB/s already scans for delimiters with vpcmpeqb. Its bottleneck is elsewhere (field values made a detour through std::string, which at 160-byte message granularity is death by allocation). The leaderboard converged on "don't stop early" without anyone writing a blog post about it, which is what leaderboards are for.
Second: Solution A does a complete parse, checksum and timestamps and all, at 10.3 GiB/s single-core, faster than our best delimiter-only tokenizer. A parser beating a tokenizer means the top tier is not winning by scanning bytes faster; it is winning by arranging to inspect fewer of them. How it does that is exactly the kind of thing that separates the top of that leaderboard from a gold badge, so it stays on the leaderboard. The part that belongs in this article is the part every tier already agrees on: the hot loop has no exit and no data-dependent branch, and the checksum math means every byte gets touched by SIMD anyway.
Methodology, and one warning about scalar benchmarks
All numbers from aorus, Threadripper 3960X (Zen 2), isolated core 18 (isolcpus + nohz_full), taskset -c 18, -O3 -march=native, four compilers (g++-13/14, clang++-18/20), 11 samples per cell, medians. IQR over median is under 3% almost everywhere: 2.1% worst in the 5.7 KB matrix, 2.8% worst in the size sweep, and 4.0% in the worst cell of the whole dataset, which is clang-20's sweep at 1% selectivity. Every fold kernel passed a verify gate (bit-identical output against a scalar reference, composed with the reported first-non-ASCII index, across a battery including planted non-ASCII bytes at the edges) before any timing was accepted; the FIX tokenizers additionally had to agree on every offset and reject every garbage-injected message. The AVX-512 table is the exception and says so: a Zen 5 laptop, pinned but not isolated, with the same harness and the same verify gate.
The warning: while assembling this dataset we caught the scalar cells moving by up to 50% between rebuilds of the same source at the same flags. One binary had gcc-13's naive loop at 0.66 GiB/s in one measurement mode and 1.98 in another; after an unrelated one-line change to the driver, five consecutive fresh runs agreed on 1.98. Nothing in the loop changed; its alignment did. Clang's naive loop similarly sat at 1.97 in our first full sweep and 1.32 in the final one. This is the classic layout sensitivity documented by Mytkowicz et al., and it is why every number in this article comes from a single binary version, and why we do not publish 1.32-vs-1.47-level comparisons between scalar variants as findings. The 22-38x cliff sits more than an order of magnitude above the worst layout swing I saw. The rung-to-rung scalar differences are not, and any article (including GitHub's) comparing 2.6 to 3.1 on single builds is inside the noise band of code placement.
What to do with this
The fold and the tokenizer point the same direction. Write the hot scan as a full-buffer sweep with no data-dependent exit, keep the rare-event answer in an accumulator, and handle the exceptional case after the loop; the exceptional case has to land in the first ~4% of the buffer before stopping early even breaks even, and if it involves a store none of the four compilers on the original rig could vectorize the exit form anyway, GCC 14's early-break support included, though GCC 16 now vectorizes the branchless spelling of it. On AVX2, write the store unconditionally, because that is not a micro-optimization, it is the permission slip the vectorizer needs there; on an AVX-512 target leave the if in, since the compiler vectorizes it with masked stores and on Zen 5 that beats the unconditional version. And if the loop's job includes reporting positions rather than just a verdict, budget your effort there: past 4 GiB/s the delimiter extraction is the bottleneck, and the people at the top of the FIX-parser leaderboard are not scanning faster than you, they are scanning less.
Review quiz
Five questions about this article. Get four right and it counts as read. Review quizzes come with a membership.
Log in See membership
Comments
No comments yet. Be the first to share your thoughts.