SUNDAY, SEPTEMBER 27, 2026
gcc Performance Win
Reassociation optimization correctly handles int128 and BitInt for rotate+xor
Reassociation optimization now correctly handles 128-bit integers and BitInt types for rotate+xor sequences.
A previous reassociation optimization that exposed rotate+xor sequences has been fixed to correctly handle int128 and BitInt types. The change replaces HOST_WIDE_INT interfaces with wi:: interfaces, resolving code generation issues on architectures like AArch64 and enabling the optimization for BitInt.
In Details
The reassociate xor to expose rotate patterns in gcc/match.pd previously used HOST_WIDE_INT which did not correctly support 128-bit integers or BitInt. This commit updates the pattern matching to use the wi:: interfaces, ensuring correct code generation for int128 (e.g., on AArch64) and enabling the optimization for BitInt types.
For Context
- reassociation
- An optimization technique that changes the grouping of associative operations (like addition or XOR) to enable other optimizations or improve instruction scheduling. For example, changing
(a + b) + ctoa + (b + c). - rotate+xor
- A specific instruction sequence pattern that combines a bitwise rotate operation with a bitwise XOR operation. Compilers often try to identify and optimize such patterns.
- int128
- A data type representing a 128-bit signed integer. GCC supports this for specific architectures and optimizations.
- BitInt
- A GCC extension for arbitrary-precision integers, allowing integers of any specified bit width.
- HOST_WIDE_INT
- A GCC internal macro representing the widest integer type available on the host machine, often used for intermediate calculations.
- wi:: interfaces
- A C++ namespace within GCC that provides interfaces for arbitrary-precision (wide) integers, used for handling types like
BitIntand large fixed-width integers.