fold-const: tree_expr_maybe_signaling_nan_p improvements
Improves NaN handling in constant folding by correctly identifying non-signaling NaN results.
GCC’s constant folding logic has been improved to more accurately identify when an expression cannot result in a signaling NaN. This commit updates tree_expr_maybe_signaling_nan_p in fold-const.cc to reflect that binary arithmetic operations and standard math functions (like sqrt, sin, cos, tan) always produce quiet NaNs, not signaling ones. This refinement helps optimization passes by reducing unnecessary caution around signaling NaNs.
In Details
The function tree_expr_maybe_signaling_nan_p in fold-const.cc is updated to correctly reflect that results of arithmetic operations and common math functions (sqrt, sin, cos, tan) are quiet NaNs, not signaling NaNs. This is because inputs to signaling NaNs are silenced to quiet NaNs. This change helps subsequent optimization passes, like those in ranger, to avoid unnecessary conservatism when dealing with NaN propagation.
- signaling NaN
- A special floating-point value (Not-a-Number) that, when used in an operation, signals an exception. This is distinct from a quiet NaN.
- quiet NaN
- A special floating-point value (Not-a-Number) that propagates through calculations without signaling an exception. Operations involving quiet NaNs typically result in a quiet NaN.
- constant folding
- An optimization technique where expressions with constant operands are evaluated at compile time rather than runtime.
- tree-ssa
- GCC's intermediate representation and optimization framework, based on Static Single Assignment form.
- NaN
- Not-a-Number, a special value in floating-point arithmetic used to represent undefined or unrepresentable results, such as the result of 0/0.