GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
internal-fn Performance Win

internal-fn: Optimize .MUL_OVERFLOW for sub-mode precision

Optimize overflow checking for __builtin_mul_overflow with smaller result precision.

This change optimizes the __builtin_mul_overflow intrinsic when the result type’s precision is smaller than its machine mode. Previously, it performed an overflow check at the mode’s precision and a redundant fit check upon storing the result. Now, it uses the result type’s precision for the overflow check and informs the store helper that overflow is already handled, eliminating the redundant check. This simplifies the expansion and ensures correctness for such cases.

In Details

The expand_mul_overflow intrinsic expansion in internal-fn.cc now correctly handles cases where the result type's precision is less than the machine mode's precision. It aligns the overflow check with the result type's precision and updates expand_arith_overflow_result_store to accept an overflow_checked flag, allowing it to skip a subsequent fit check. This addresses PR116135 by ensuring overflow is detected based on the target precision.

For Context
__builtin_mul_overflow
A GCC intrinsic function that performs multiplication and checks if the operation resulted in an overflow. It returns a boolean indicating overflow and stores the result in a pointer argument.
machine mode
A representation of data types within GCC, specifying their size and internal representation, such as SI for single integers or DI for double integers.
precision
In the context of _BitInt, precision refers to the exact number of bits a variable can hold, which might be smaller than the machine mode's capacity.
Filed Under: optimizationcompiler-intrinsics