GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match.pd Performance Win

Fold sign-bit operations on reinterpreted floats

Optimizes floating-point sign bit manipulation by folding them into standard absolute value and negation operations.

This change optimizes code that manipulates the sign bit of floating-point numbers using integer reinterpretations. Previously, such operations would involve moving values between floating-point and integer registers, leading to inefficiencies. The compiler now recognizes these patterns and canonicalizes them to ABS_EXPR or NEGATE_EXPR, allowing them to be lowered to native target instructions and combine better with surrounding code. This improves performance by reducing register pressure and leveraging efficient hardware instructions, particularly for operations like fabs, negation, and copysign.

In Details

This commit introduces a new optimization in the match.pd pass for GCC. It targets GIMPLE expressions where floating-point values are cast to integers, their sign bit is manipulated (cleared, flipped, or set using bitwise operations), and then cast back to floating-point. The optimization recognizes these patterns as equivalent to fabs, negation, or negation of fabs. It canonicalizes these into ABS_EXPR and NEGATE_EXPR at the GIMPLE level, enabling further optimization by downstream passes and target-specific lowering, especially when targets lack direct hardware support or have spe…

For Context
GIMPLE
GCC's internal representation of code between the front-end and the back-end. It's a three-address, low-level representation that facilitates optimizations.
VIEW_CONVERT_EXPR
An expression in GCC's internal representation indicating a conversion between types, often used when reinterpreting the bits of one type as another, like casting a float to an integer to access its bit pattern.
ABS_EXPR
An expression in GCC's internal representation representing the absolute value of an operand.
NEGATE_EXPR
An expression in GCC's internal representation representing the negation of an operand.
copysign
A function that returns a value with the magnitude of the first argument and the sign of the second argument.
NaN
Not a Number. A special floating-point value used to represent undefined or unrepresentable results, such as the result of 0/0.
signed zero
Floating-point numbers can have both a positive zero (+0.0) and a negative zero (-0.0). While they compare as equal, their bit representations differ.
bfloat16
A 16-bit floating-point format with a similar exponent range to IEEE 754 single-precision but lower precision.
Filed Under: optimizationfloating-pointGIMPLE