TUESDAY, AUGUST 18, 2026
tree-optimization
Fix crash in loop IV optimization due to missed folding
Avoid a crash in loop IV optimization when simplifying an induction variable candidate to zero.
This commit addresses a crash in the loop invariant code (IVOPTs) optimization pass. Previously, if a simplification of an induction variable candidate resulted in a zero step, the Scalar Evolution (SCEV) analysis might still consider it an IV with a zero step. This change prevents a crash by handling cases where the IV is invariant.
In Details
The tree-ssa-loop-ivopts.cc file's create_new_iv function now guards against crashing when an invariant IV is encountered due to prior SCEV simplification. This handles a corner case where the IV step simplifies to zero, but the IV itself remains invariant, which could lead to unexpected states in the optimization.
For Context
- IVOPTs
- Loop Invariant Code Motion optimization. It identifies computations within a loop that do not change with each iteration and moves them outside the loop to improve performance.
- SCEV
- Scalar Evolution analysis. A compiler analysis that computes properties of values that evolve arithmetically over loops, such as induction variables.
- Induction Variable
- A variable that is updated by a constant amount in each iteration of a loop, typically used for loop control or array indexing.