[Bug tree-optimization/126467] [13/14/15/16/17 Regression] wrong code with folding 0.0 - x

roger at nextmovesoftware dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126467

--- Comment #2 from Roger Sayle <roger at nextmovesoftware dot com> ---
The problem is with the transformation at line 5916 of match.pd:

/* (ARG0 - ARG1) is the same as (-ARG1 + ARG0).  So check whether
   ARG0 is zero and X + ARG0 reduces to X, since that would mean
   (-ARG1 + ARG0) reduces to -ARG1.  */
(simplify
 (minus real_zerop@0 @1)
 (if (fold_real_zero_addition_p (type, @1, @0, 0))
  (negate @1)))

The problem is that "x - y" is not the same as "(-y) + x" in IEEE FP,
i.e. the first sentence/statement of the comment is incorrect, so it's
inappropriate to use fold_real_zero_addition_p here.  Instead it needs
to check that y can't be zero (or signaling NaN).  Technically, if
x is +0.0, it's OK for y to be -0.0.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.