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

Use __builtin_bitreverse64 for emulation if supported.

Replaces naive bitreverse emulation with a faster intrinsic, improving performance and bootstrapping.

The reflect_hwi function in hwint.cc previously used a slow loop to emulate __builtin_bitreverse64. This commit replaces that loop with a direct call to the intrinsic function when supported, offering a significant performance improvement. It also introduces STAGE0_CXX_HAS_BUILTIN in system.h to check for specific builtins, ensuring broader compatibility and better bootstrapping for GCC.

In Details

This change updates hwint.cc to use STAGE0_CXX_HAS_BUILTIN for __builtin_bitreverse64. Previously, reflect_hwi used a naive loop, which is now replaced by the intrinsic for better performance, especially relevant during bootstrapping. The ira-color.cc file also adopts this macro, removing a manual check for HAS_SMUL_OVERFLOW.

For Context
__builtin_bitreverse64
A GCC intrinsic function that reverses the bits of a 64-bit integer. Using built-in intrinsics is generally faster than a software emulation.
STAGE0_CXX_HAS_BUILTIN
A preprocessor macro used during GCC's early build stages (stage 0) to conditionally enable compiler builtins. This allows the compiler to leverage optimized intrinsic functions when available.
bootstrapping
The process of compiling a compiler using an earlier version of itself. This helps ensure the compiler's self-consistency and is a crucial part of the build process.
Filed Under: performanceoptimizationbuiltins