[Bug middle-end/93806] Wrong optimization: instability of floating-point results with -funsafe-math-optimizations leads to nonsense
ch3root at openwall dot com
gcc-bugzilla@gcc.gnu.org
Thu Feb 20 20:58:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93806
--- Comment #8 from Alexander Cherepanov <ch3root at openwall dot com> ---
A similar problem happens with -fno-signed-zeros -fno-trapping-math. Not sure
if a separate PR should be filed...
----------------------------------------------------------------------
#include <stdio.h>
__attribute__((noipa)) // imagine it in a separate TU
static double opaque(double d) { return d; }
int main()
{
int zero = opaque(0);
double x = opaque(-0.);
int a = 1 / x == 1 / 0.;
printf("zero = %d\n", zero);
opaque(a);
if (zero == a) {
opaque(0);
if (x == 0) {
opaque(0);
if (a) {
opaque(0);
if (zero == 1)
printf("zero = %d\n", zero);
}
}
}
}
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -fno-signed-zeros -fno-trapping-math -O3
test.c && ./a.out
zero = 0
zero = 1
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200220 (experimental)
----------------------------------------------------------------------
More information about the Gcc-bugs
mailing list