PR tree-optimization/124715: pow(0,-1) sets errno with -fmath-errno
GCC now avoids transforming pow(x,-1) into 1.0/x when x could be zero and `-fmath-errno` is enabled, preventing incorrect errno settings.
GCC now respects the -fmath-errno flag when optimizing pow(x, -1) to 1.0/x. The transformation is disabled when x might be zero and -fmath-errno is active, because 1.0/0.0 sets errno while pow(0.0, -1.0) does not. This ensures that the compiler generates code that correctly sets errno when required, improving correctness for programs that rely on this behavior.
In Details
This patch addresses PR tree-optimization/124715 by adding a check for flag_errno_math in match.pd before simplifying pow(x, -1) to 1/x when x could be zero. This prevents incorrect errno settings due to the difference in behavior between pow(0.0, -1.0) and 1.0/0.0. The change ensures that the compiler respects the -fmath-errno flag and generates code that adheres to the expected errno behavior.
For Context
The -fmath-errno compiler flag tells GCC to generate code that sets the errno variable according to the C standard. Some math functions, like pow(), have specific error-handling behaviors that affect errno. This commit fixes an optimization that could change how errno is set in certain cases. Specifically, it prevents GCC from replacing pow(x, -1) with 1.0/x when x might be zero and -fmath-errno is used, as these two expressions have different errno semantics.