Odd optimizer behavior with FP arithmetic
Konstantin Shegunov
kshegunov@gmail.com
Thu Sep 26 16:53:00 GMT 2019
Hello,
I have a piece of floating point EFT arithmetic in my code, but I get a
rather strange code generation for it. Here's the actual source code and
flags I've experimented with: https://godbolt.org/z/oJEs4U
The first pane is what I expect to get as output, that is, all the
arithmetic operations in the assembly. However the strange thing is I have
to compile with -funsafe-math-optimizations to actually produce that.
The second pane is the same thing but with -fno-unsafe-math-optimizations
(default) and surprisingly the optimizer strips the relevant instructions.
I would've thought the -fno-associative-math enough to prevent that from
happening but for some reason it's not.
The third pane I added for good measure. It illustrates the same flags as
the first one (the one that generates the correct assembly), but the flags
are applied through an attribute directly to the symbol. Even more
surprisingly this generates yet another completely different piece of
output, which doesn't even seem to do what's supposed to (unsafe means
unsafe in this case, I gather).
Has anyone any insight into this?
Why isn't -fno-associative-math enough in stopping the optimizer here?
Why would -funsafe-math-optimizations actually trigger the correct code
being generated?
And as a curiosity, why would it matter if the flag is applied to the
symbol in contrast to the pragma?
Thanks in advance!
Konstantin.
More information about the Gcc-help
mailing list