GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
simplify-rtx

Preserve FP trap behavior when combining comparisons

Fixes incorrect trapping behavior when simplifying floating-point comparisons with NaNs.

A bug in simplify_logical_relational_operation caused incorrect floating-point trap behavior when combining comparisons involving NaNs and -ftrapping-math. The simplification could either add a trap where none existed or remove an existing trap. This change corrects the behavior by ensuring the combined comparison preserves the trapping semantics of the original comparisons, particularly concerning quiet NaNs.

In Details

The simplify_logical_relational_operation pass in simplify-rtx.cc was not correctly accounting for floating-point comparison predicates that signal exceptions on quiet NaNs (e.g., LT, GT, ORDERED). When combining such predicates, especially under -ftrapping-math, the pass could alter the exception-signaling behavior. This commit introduces comparison_mask_signals_p and refines simplify_logical_relational_operation to refuse combinations that change the trap behavior for quiet NaNs, aligning with fold-const.cc's combine_comparisons logic. Added selftests cover various compa…

For Context
NaN
Not a Number. A special floating-point value used to represent undefined or unrepresentable results, such as the result of 0/0. Quiet NaNs propagate through calculations without raising an exception, while signaling NaNs can raise exceptions.
-ftrapping-math
A GCC optimization flag that enables trapping behavior for floating-point operations that would normally produce a NaN or infinity. This can detect certain floating-point exceptions at runtime.
RTX
Representation of intermediate language in GCC. RTX is a Lisp-like language used to represent the program's structure and operations internally within the compiler.
Quiet NaN
A type of NaN that does not raise a floating-point exception when used in an operation. It propagates through computations, allowing for deferred error handling.
Filed Under: bugfixfloating-pointsimplification