https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106805
Bug ID: 106805 Summary: Undue optimisation of floating-point comparisons Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: fxcoudert at gcc dot gnu.org Target Milestone: --- With current gcc trunk, on x86_64-linux: $ cat a.c #include <math.h> #include <stdio.h> #include <fenv.h> void foo (void) { if (fetestexcept (FE_INVALID) & FE_INVALID) printf("Invalid raised\n"); feclearexcept (FE_ALL_EXCEPT); } static inline int iseqsig(float x, float y) { return (x >= y && x <= y); } int main (void) { float x = __builtin_nanf(""); float y; printf("%d\n", iseqsig(__builtin_nanf(""), 1.)); foo(); printf("%d\n", iseqsig(x, __builtin_inff())); foo(); } $ ./bin/gcc a.c -lm -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans -O0 && ./a.out 0 Invalid raised 0 Invalid raised $ ./bin/gcc a.c -lm -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans -O1 && ./a.out 0 0 The comparisons should raise FE_INVALID in all cases, and not be optimised away.