tree-optimization: Reset SCEV after predcom without unrolling
SCEV results are now reset after loop predictive commoning when a loop is transformed but not unrolled, fixing a bug in invariant calculation.
A bug in tree-optimization’s predictive commoning pass caused Scalar Evolution (SCEV) results to be cached even when loops were transformed without unrolling. This led to incorrect invariant calculations in subsequent passes like ivopts, preventing optimizations such as strength reduction of stores. The issue occurred because SCEV results were only reset when loops were unrolled or underwent significant SSA fixups. This commit modifies the pass to reset SCEV whenever any loop transformation occurs, regardless of unrolling, ensuring accurate invariant analysis and enabling more optimizations at optimization levels like -O2.
In Details
This commit addresses a caching issue within tree_predictive_commoning related to Scalar Evolution (SCEV) analysis. Previously, tree_predictive_commoning only reset its cached SCEV data-reference analysis results if a loop was unrolled or required loop-closed SSA fixup (indicated by changed > 1). In common scenarios at -O2 (where predcom runs implicitly via -ftree-loop-vectorize without unrolling), these cached results would persist. This led to ivopts using stale SCEV information, causing it to miss opportunities like strength-reducing stores because it didn't detect the loop's…
- tree-optimization
- A phase in GCC that operates on the SSA (Static Single Assignment) form of the code, performing various high-level optimizations.
- SCEV
- Scalar Evolution. A compiler analysis technique used to determine properties of loop-invariant values and induction variables, crucial for loop optimizations.
- predcom
- Predictive Commoning. A compiler optimization pass that hoists loop-invariant computations outside the loop.
- unrolling
- A loop optimization technique where the loop body is duplicated multiple times to reduce loop overhead and expose more opportunities for instruction-level parallelism.
- SSA
- Static Single Assignment. An intermediate representation where every variable is assigned a value exactly once, simplifying many optimization analyses.
- ivopts
- Invariant Vector Optimization. A compiler pass that optimizes loops by identifying and moving loop-invariant computations out of the loop body.