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

Hoist shift by out-of-range count to reduce it

Optimize shifts with potentially out-of-range counts by hoisting and reducing them.

This change improves loop optimizations by handling shifts with unknown or out-of-range counts. Previously, such shifts could be costly or lead to incorrect masking, impacting vectorized loops. The optimization now hoists the shift operation, reduces the shift count to be within the valid range, and correctly costs the operation, preventing unnecessary masking and improving performance in certain loop scenarios.

In Details

The gimple_needing_rewrite_undefined predicate in gimple-folding now accepts a SHIFT_COUNT parameter. When true, it identifies shifts or rotates where the count might be out of range. The rewrite_to_defined_unconditional function then reduces this count. The tree-ssa-loop-im.cc pass is updated to cost these potentially out-of-range shifts as cheap, and movement_possibility_1 now correctly handles cases where the count cannot be reduced or the loop is size-optimized.

Filed Under: optimizationloop-optimizationsgimple