[Bug middle-end/93806] Wrong optimization: instability of floating-point results with -funsafe-math-optimizations leads to nonsense

vincent-gcc at vinc17 dot net gcc-bugzilla@gcc.gnu.org
Fri Feb 21 01:26:00 GMT 2020


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

--- Comment #11 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Rich Felker from comment #10)
> I don't think it's at all clear that -fno-signed-zeros is supposed to mean
> the programmer is promising that their code has behavior independent of the
> sign of zeros, and that any construct which would be influenced by the sign
> of a zero has undefined behavior. I've always read it as a license to
> optimize in ways that disregard the sign of a zero or change the sign of a
> zero, but with internal consistency of the program preserved.

But what does "internal consistency" mean? IMHO, if you choose a strict, safe
meaning, then the optimization option is likely to have no effect in practice.

An example:

int foo (double a)
{
  double b, c;
  b = 1 / a;
  c = 1 / a;
  return b == -c;
}

If a is a zero, would you regard a result 1 as correct? Some users may regard
this as inconsistent, since even though they do not care about the sign of zero
when computing a value, they may assume that the sign of a will not change
magically.


More information about the Gcc-bugs mailing list