tree-optimization: Avoid overflow in vector loop epilog initialization
Prevents undefined behavior from integer overflow when calculating vector loop epilog start values.
This commit resolves an undefined behavior issue in the vectorizer by using an unsigned type to compute the start value of loop epilogs. This prevents potential overflow during the calculation of init + step * vect-niters, ensuring more reliable loop transformations.
In Details
Fixes PR tree-optimization/127588 by modifying vect_update_ivs_after_vectorizer in tree-vect-loop-manip.cc. The computation for the epilog IV start value, previously init + step * vect-niters, could overflow. By using an unsigned type for this calculation, the compiler now correctly handles potential overflows, avoiding undefined behavior and ensuring accurate loop invariant (IV) updates after vectorization.
- vectorizer
- A compiler pass that transforms scalar code into vector code, using special CPU instructions to perform operations on multiple data elements simultaneously.
- loop epilog
- The portion of a loop that executes after the main vectorized part, typically to handle any remaining iterations that did not fit into the vector width.
- invariant (IV)
- Induction variable. A variable in a loop whose value changes predictably with each iteration, often used as a loop counter or for array indexing.
- undefined behavior (UB)
- Behavior that results from an erroneous program construct or invalid input, for which the C++ standard imposes no requirements. Compilers may assume UB does not happen, leading to unexpected results.