Constant fold pow(-Inf, 0.5) and other infinite/NaN cases
Improves constant folding for pow() with infinite or NaN arguments.
GCC can now constant fold pow() operations involving infinite or NaN arguments, such as pow(-Inf, 0.5). Previously, it only handled finite arguments. This enhancement required adding real_isoddinteger and improving real_isinteger in real.cc. A new test case ensures correctness.
In Details
The fold_const_pow function in fold-const-call.cc has been enhanced to handle constant folding of pow(base, exponent) where base or exponent are IEEE 754 infinity or NaN values. This required introducing real_isoddinteger in real.cc to correctly identify odd integer exponents, particularly for binary floating-point formats. The implementation conservatively checks for a base of 2 in the floating-point representation to ensure correctness, and the real_isinteger function was also updated for efficiency.
- constant folding
- An optimization technique where expressions with constant operands are evaluated at compile time rather than runtime.
- NaN
- Not a Number. An IEEE 754 floating-point value representing an undefined or unrepresentable numerical result.
- IEEE 754
- The standard for floating-point arithmetic, defining formats, operations, and exception handling.