3 ms·
This pragma doesn't quite work for -ffast-math https://gcc.godbolt.org/z/voMK7x7hG https://gcc.godbolt.org/z/voMK7x7hG Try it with and without the pragma, and
by nly 5y ago
This pragma doesn't quite work for -ffast-math
https://gcc.godbolt.org/z/voMK7x7hG https://gcc.godbolt.org/z/voMK7x7hG
Try it with and without the pragma, and adding -ffast-math to the compiler command line. It seems that with the pragma sqrt(x) * sqrt(x) becomes sqrt(x*x), but with the command line version it is simplified to just x.
- gpderetta 5y agoThat's very interesting. The pragma does indeed do a lot of optimizations compared to no-pragma (for example it doesn't call sqrtf at all), but the last simplification is only done with the global flag set. I wonder if it is a missed optimization or if there is a reason for that. edit: well with pragma fast-math it appears it is simply assuming finite math and x>0 thus skipping the call to the sqrtf as there are not going to be any errors, basically only saving a jmp. Using pragma finite-math-only and an explicit check are enough to trigger the optimization (but passing finite-math as a command line is not). Generally it seems that the various math flags behave slightly differently in the pragma/attribute.