tree-optimization: Fold sign-changing conversions in IVOPTS
Improved loop invariant code motion by folding sign-changing conversions and handling modular arithmetic.
This commit enhances the Loop Invariant code Motion (IVOPTS) pass by enabling the ‘ranger’ analysis to fold sign-changing conversions and modular arithmetic into exact arithmetic. This resolves a code-size regression caused by canonicalizing signed arithmetic to unsigned, which previously hid loop invariant terms. The improvements allow for better affine decomposition and can reduce loop-bound spills, leading to performance gains on various architectures.
In Details
The IVOPTS pass now enables the ranger analysis and passes its range context information to tree-affine. This allows aff_combination_convert and expr_to_aff_combination to fold value-preserving sign changes and modular arithmetic into exact arithmetic, which aids affine decomposition. Specifically, it addresses cases where conversions created chains hiding outer-loop IV terms. The get_computation_aff_1 function now passes the use statement to tree-affine, and tree_ssa_iv_optimize enables ranger, improving the analysis of loop invariants and reducing code size regressions.
- IVOPTS
- Invariant Code Motion optimization pass in GCC, responsible for moving loop-invariant computations out of loops to improve performance.
- ranger
- A GCC analysis pass that computes ranges of values for variables, providing context for other optimizations.
- affine decomposition
- A process in compiler optimization that represents expressions or transformations as affine functions (linear functions with a constant offset), useful for analyzing loops and memory accesses.
- modular arithmetic
- Arithmetic where numbers 'wrap around' after reaching a certain value, like calculations with unsigned integers.
- loop-invariant
- A computation within a loop whose result does not change with each iteration of the loop.