GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
vect

Vectorization: Refactor loop peeling for early exits.

Refactors loop peeling to handle early exits more explicitly, preparing for optimizations that avoid epilogues.

This patch refactors loop peeling to better handle early exits during vectorization. This change is a preliminary step towards optimizing early break vectorization, where certain loops may not require an epilogue at all. The refactoring ensures that peeling gets an extra parameter to indicate how to handle multiple exits, and it improves the consistency of peeling between early break and uncounted loops. This makes the code more robust regarding needed optimizations.

In Details

The patch modifies slpeel_tree_duplicate_loop_to_edge_cfg in tree-vect-loop-manip.cc to add a redirect_exits parameter, which is then used in vect_do_peeling. This change addresses an interaction with uncounted loops where PHI nodes were not consistently placed in the final merge block. The refactoring ensures that all BB now explicitly mention and use all PHI nodes from the exits, making the code more robust.

For Context

Loop peeling is a loop transformation technique where the first few iterations of a loop are duplicated outside the loop. Vectorization is a compiler optimization that transforms code to perform operations on multiple data elements simultaneously. Early exits occur when a loop terminates prematurely based on a condition. This refactoring prepares the vectorizer to better handle early exits, allowing for future optimizations where the loop epilogue can be avoided completely, leading to improved performance.

Filed Under: vectorizationloop peelingoptimization