GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match

MATCH: fold signbit comparison and conditional negate to copysign [PR109843]

MATCH rule simplifies signbit comparisons and conditional negations into copysign operations.

A new rule has been added to the GCC MATCH optimization patterns to recognize and simplify a common code sequence involving sign bit comparisons and conditional negations. The pattern (signbit (x) cmp1 0) cmp (signbit (y) cmp2 0) ? y : -y is now folded into a copysign(y, +-x) operation. This transformation preserves the magnitude of y while taking its sign from x (or -x), and can be emitted as IFN_COPYSIGN on supporting targets, leading to more efficient code for operations like copysign and potentially improving performance.

In Details

A new MATCH pattern simplifies expressions of the form (signbit(x) cmp 0) cmp (signbit(y) cmp 0) ? y : -y to copysign(y, +-x). This replaces a conditional operation based on signs with a single copysign intrinsic, targeting PR109843 and preparing for potential IFN_COPYSIGN emission.

For Context
MATCH
A framework within GCC used for defining and applying machine-specific or generic tree-based optimizations.
signbit
A function that returns a true value if the most significant bit (sign bit) of a number is set, indicating a negative value for signed number representations.
copysign
A function that returns a value with the magnitude of one argument and the sign of another. For example, copysign(x, y) returns the magnitude of x and the sign of y.
fold
An optimization where a complex expression is replaced by a simpler, equivalent one.
IFN_COPYSIGN
Likely an internal GCC or target-specific intrinsic representation for the copysign operation, possibly more efficient than a standard C library call.
PR109843
A Problem Report number in GCC's bug tracking system, referencing a specific issue that this commit addresses.
Filed Under: optimizationMATCHcopysign