Is there a way to disable ALL "optimizations" related to floating-point? My testing has shown that clang does the following: 1. * x => x 0. * x => 0. x / 1. => x x / x => 1. 0. / x => 0. x + 0. => x x - 0. => x x - x => 0. They are all invalid "optimizations" if x is a signaling NaN. In addition, some are invalid if x is a signed zero or infinity. In the above, 'x' can be either a variable or a constant. It might matter if 'x' is float, double, or long double.
Currently clang and llvm assume that floating point generates no side effects. There is work in progress to teach llvm and clang to be strict with floating point so many optimizations don't fire. If you want to follow the progress the tickets at reviews.llvm.org tend to have "[FPEnv]" in the name somewhere, and this is sometimes true for the mailing lists as well. See also the "constrained floating point intrinsics" in the Language Reference: https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics
I am glad to see that some work is being done on this issue. http://www.tybor.com/tflt2int.c is a good test case for ‘llvm.experimental.constrained.fptoui’ Intrinsic ‘llvm.experimental.constrained.fptosi’ Intrinsic However, it appears to me that those intrinsics would not work for integer bit fields with respect to raising invalid for FP numbers too big to fit.
It is a work in progress. I haven't looked at bitfields, but this ticket may get us closer: "Add constrained int->FP intrinsics" https://reviews.llvm.org/D69275
Created attachment 23677 [details] Command line options for clang to try to get good floating-point conformance clang command line options to try to get conformance to IEEE-754 and Standard C.
With those command line options, the test case http://www.tybor.com/tflt2int.c still is getting 183 failures. I tried those options after reading bug 8100. I tried what it suggested and reporting a bug in that 'fix'.