Fix GCC pow folding for edge cases and errno handling.
GCC's power function folding is corrected for edge cases and improved to handle errno correctly.
This commit addresses two issues in GCC’s middle-end optimization related to the pow() function. It corrects inaccuracies in folding pow(-Inf, x) and resolves an older math-errno issue. The fix ensures that pow(x,-1) is only transformed when flag_errno_math is false, preventing incorrect transformations when errno might be updated.
In Details
GCC's match.pd and real.cc are updated to correct pow folding. The transformation pow(x,-1) -> 1/x is now guarded by !flag_errno_math to prevent incorrect folding when errno may be set. Additionally, real_isoddinteger has been fixed to correctly identify odd integers by ensuring fractional bits are zero. These changes resolve PR tree-optimization/128135 and PR middle-end/128138.
- folding
- In compilers, 'folding' refers to the optimization of replacing an expression with its computed constant value at compile time.
- pow()
- The standard C math library function that computes a base to the power of an exponent (base^exponent).
- errno
- A global integer variable in C that holds the error number set by system calls and some library functions, indicating the cause of a failure.
- flag_errno_math
- A compiler flag or internal state indicating whether math functions in the compiled code are expected to set the 'errno' variable.
- RTL
- Register Transfer Language, an intermediate representation used by GCC to represent code before it is translated into machine code.