GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/vect Performance Win

Correctly handle loop exit conditions for vectorized do-while loops

Fixes vectorized do-while loops that exit one iteration early due to incorrect loop edge handling.

This commit corrects an issue where vectorized loops with early exit conditions, specifically those resembling do-while loops (marked with LOOP_VINFO_EARLY_BREAKS_VECT_PEELED), were exiting one iteration prematurely. This occurred because the loop’s iteration variable check was incorrectly processed relative to the loop latch. The fix ensures the loop condition is checked correctly, preventing unnecessary early exits and ensuring all intended iterations are processed before termination or branching to scalar code. This resolves an issue seen in specific AArch64 code generation scenarios.

In Details

The vectorizer's handling of loops that exhibit a do-while control flow pattern, identified by LOOP_VINFO_EARLY_BREAKS_VECT_PEELED, was flawed. Specifically, the loop condition check was performed in a way that caused it to evaluate one iteration too early relative to the loop body's execution. This resulted in the loop terminating before the last intended iteration, especially when combined with partial masked vectorization. The fix involves adjusting how loop edges and iteration variable updates are processed to ensure the loop condition accurately reflects the loop's progress, maintainin…

For Context
Vectorizer
A compiler component that transforms loops operating on single data elements into loops that operate on multiple data elements simultaneously using SIMD instructions.
do-while loop
A control flow structure that executes a block of code at least once, then checks a condition to determine if the block should be executed again.
Loop PEELED
Loop peeling is an optimization where one or more iterations of a loop are "peeled off" and executed before the main loop body. This can help in loop unrolling or handling specific loop structures, like do-while loops, more effectively for vectorization.
Iteration Variable (IV)
A variable that is incremented or decremented in each iteration of a loop, typically used to control the loop's termination.
Preheader
A basic block that unconditionally branches to the loop header. It's often used to hoist loop-invariant computations or set up loop control variables.
Filed Under: gcc/vectvectorizationloop optimizationaarch64