GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386

i386: VCOMX used for FP EQ/NE only when NaNs are honored

The i386 backend now restricts the use of VCOMX for floating-point comparisons to cases where NaN handling is enabled.

On x86, the VCOMX instruction is now used for floating-point equality (EQ) and inequality (NE) comparisons only when the compiler is configured to honor NaN (Not-a-Number) values. Previously, VCOMX was used unconditionally, which could lead to unnecessary code generation and performance degradation when NaNs were not relevant. This change optimizes comparison logic by avoiding VCOMX when simpler instructions suffice, preventing unintended SSE to GPR moves.

In Details

This commit modifies ix86_expand_fp_compare to conditionally emit UNSPEC_OPTCOMX. This intrinsic is now only used when HONOR_NANS is true. Without this flag, standard COMI instructions combined with the ZF flag are sufficient for EQ/NE checks, avoiding the overhead and potential subsequent register moves associated with UNSPEC_OPTCOMX.

For Context
VCOMX
An SSE/AVX instruction intrinsic used for floating-point comparisons. UNSPEC_OPTCOMX is GCC's internal representation for a specific variant of this operation.
NaN
Not a Number. A special floating-point value used to represent undefined or unrepresentable results, such as from 0/0 or sqrt(-1).
HONOR_NANS
A GCC target configuration macro that indicates whether floating-point comparisons should correctly handle NaN values according to the IEEE 754 standard.
EQ/NE
Equality and Not-Equal comparison operations for floating-point numbers.
COMI
A comparison instruction on x86 that sets flags based on the comparison result. It can be used for EQ/NE checks.
ifcvt
An x86 instruction related to conditional moves or conversions, often used in conjunction with floating-point comparisons.
Filed Under: x86floating-pointoptimization