GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
scev Performance Win

Scev: Sign extend step in peeled converted IV handling [PR 125291]

GCC's scalar evolution analysis now correctly handles peeled converted induction variables by sign-extending the step.

GCC’s scalar evolution (SCEV) analysis now correctly handles peeled converted induction variables (IVs) by sign-extending the step. In cases where a converted IV is peeled (unrolled a few times), the analysis could incorrectly compute the sequence of values, leading to incorrect constant propagation. Sign-extending the step ensures the analysis accurately tracks the IV’s value across iterations. This fixes PR 125291, where an unsigned char was being misinterpreted as a large positive number instead of a negative offset.

In Details

This commit modifies simplify_peeled_chrec in tree-scalar-evolution.cc to sign-extend the step for peeled converted IVs. The previous implementation could misanalyze the value range of the IV, leading to incorrect VRP intersections and constant propagation. The fix addresses PR tree-optimization/125291, where an unsigned char step was not correctly sign-extended. A new test case gcc.c-torture/execute/pr125291.c is added to verify the fix.

For Context

Scalar Evolution (SCEV) is a compiler analysis technique that aims to understand how variables change over the course of a loop. Induction variables are variables which are incremented or decremented by a constant amount on each iteration of a loop. Peeled loops are loops that have their first few iterations unrolled. This commit fixes an issue in how GCC analyzes peeled loops with induction variables, ensuring that the compiler correctly understands how these variables change, leading to better optimization.

Filed Under: scevscalar evolutioninduction variableloop optimizationtree-optimization