GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

Fix missing may_be_zero check in final value replacement

Corrected a scalar evolution analysis to prevent incorrect XOR parity mask computation.

The final value replacement pass in the tree optimizer previously failed to check niter_desc.may_be_zero. This omission could lead to incorrect computation of the XOR parity mask when a loop might exit on its first iteration. The fix ensures this check is performed, preventing the use of invalid iteration counts.

In Details

This commit corrects an issue in final_value_replacement_loop within tree-scalar-evolution.cc. The analyze_and_compute_bitop_with_inv_effect function was called without guarding on niter_desc.may_be_zero. This could lead to incorrect calculations if the loop condition allowed for early exit. The change adds a check for integer_zerop(niter_desc.may_be_zero) to ensure the XOR parity mask is computed only when the number of iterations is valid.

For Context
tree-optimization
A phase in GCC where the code is represented and manipulated using an intermediate 'tree' structure, allowing for various optimizations.
scalar evolution
A compiler analysis technique that determines properties of expressions involving induction variables in loops, such as their rate of change.
XOR parity mask
A bitmask used in certain computations, where the parity (evenness or oddness) of set bits is determined using the XOR operation. This is often relevant in loop analysis or bit manipulation optimizations.
Filed Under: optimizationloop analysis