https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64225
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wschmidt at gcc dot gnu.org --- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to ktkachov from comment #7) > (In reply to ktkachov from comment #6) > > fold-const.c has a comment in the relevant case that says: > > /* Canonicalize x*x as pow(x,2.0), which is expanded as x*x. */ > > I think this comment is misleading. > In builtins.c the expand_builtin_mathfn_2 handles the expansion of pow and I > don't see any code to expand pow (x, 2.0) as x * x. It tries to use the pow > optab, so unless the backend explicitly expands the case in such a manner, > it will not be converted to x*x. > > Is there some other place in the compiler that plays a role here? The sincos pass in tree-ssa-math-opts.c expands pow with integer exponent to an optimal multiplication sequence. But this is just guarded with flag_unsafe_math_optimizations, so I don't see where you get the -fmath-errno issue. In fact I can reproduce the issue on x86_64-linux and the issue is that reassociation creates powi (d, 2) but does not remove the original pow call which ends up not being DCEd because of the errno setting. CCing author. The simplest patch would be to reject the transform with -fmath-errno like with (pre-approved) Index: gcc/tree-ssa-reassoc.c =================================================================== --- gcc/tree-ssa-reassoc.c (revision 218479) +++ gcc/tree-ssa-reassoc.c (working copy) @@ -3988,6 +3988,9 @@ acceptable_pow_call (gimple stmt, tree * switch (DECL_FUNCTION_CODE (fndecl)) { CASE_FLT_FN (BUILT_IN_POW): + if (flag_errno_math) + return false; + *base = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1);