Bitintlower: Improve `__builtin_` lowering for bit operations on `_BitInt` types
GCC now generates more efficient code for bit manipulation and byte-swapping built-in functions when used with `_BitInt` types, avoiding unnecessary memory cop…
GCC’s bitintlower pass has been enhanced to produce more optimized code for built-in functions like __builtin_bswapg and __builtin_clz when they operate on _BitInt types. Previously, the compiler would often copy _BitInt values to temporary storage before performing these operations. The updated lowering logic now allows direct operations on values in memory and can merge bswap/bitreverse results with subsequent store operations, significantly reducing unnecessary memory movements and improving performance, especially for larger _BitInt values.
In Details
The bitintlower pass in GCC is responsible for lowering _BitInt types, which are arbitrary-precision integers, into a representation suitable for the target architecture. This commit specifically targets the lowering of internal functions (IFN_BSWAP, IFN_BITREVERSE, IFN_CLZ, IFN_CTZ, IFN_CLRSB, IFN_FFS, IFN_PARITY, IFN_POPCOUNT) when applied to _BitInt operands within gimple-lower-bitint.cc. The improvement avoids redundant memory copies (load-op-store patterns) by allowing direct operations on memory locations where possible and merging the results of bit manipulation…
For Context
In programming, _BitInt is a special type of number that can hold an arbitrary number of bits, unlike standard integers which usually have fixed sizes like 32 or 64 bits. This is useful for specialized mathematical or cryptographic operations. Compilers like GCC have "built-in" functions (e.g., __builtin_bswapg for reversing byte order, or __builtin_clz for counting leading zeros) that work very efficiently, often by using special CPU instructions. This update makes GCC much better at handling these built-in functions when you use them with _BitInt numbers. Previously, the compiler might unnecessarily copy large _BitInt values around in memory before performing the operation, which is slow. Now, it can often perform these operations directly on the number where it sits in memory or combine the operation with saving the result back to memory, leading to faster and more efficient programs when using _BitInt types.