https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123958

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |roger at nextmovesoftware dot 
com
           Assignee|unassigned at gcc dot gnu.org      |roger at 
nextmovesoftware dot com

--- Comment #5 from Roger Sayle <roger at nextmovesoftware dot com> ---
Doh!  This is caused by tree-ssa-math-opts attempting for convert pow(x,2.0)
into a fused multiply add, which is incorrect for flag_errno_math. One possible
fix would be:

diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index 469de10a432..78c3637efe9 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -6598,7 +6598,8 @@ math_opts_dom_walker::after_dom_children (basic_block bb)
          switch (gimple_call_combined_fn (stmt))
            {
            CASE_CFN_POW:
-             if (gimple_call_lhs (stmt)
+             if (!flag_errno_math
+                 && gimple_call_lhs (stmt)
                  && TREE_CODE (gimple_call_arg (stmt, 1)) == REAL_CST
                  && real_equal (&TREE_REAL_CST (gimple_call_arg (stmt, 1)),
                                 &dconst2)

but a better solution might be for convert_mult_to_fma to be more robust, and
figure out which transformation it's depending upon, and return false if that
transformation doesn't happen.  In future, given ranger's bounds on x it might
be ok to always transform pow(x,2.0) to x*x, but this isn't universally true,
so duplicating the flag_errno_math test above isn't an ideal (long term)
solution.

Any advice on a better fix (while I investigate)?  I'll bootstrap and
regression test the above to have a quick (temporary) fix in GCC for stage 4.

Reply via email to