http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57866
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> --- There is no constant folding going on, the compiler simply sees the addition as dead code. To work around it, you would need to introduce a use of result, which would disable this tree optimization, but then you would get constant propagation indeed at the RTL level, so you also need to hide the constants from the compiler (with volatile or some asm). gcc has a -ftrapping-math option. It is not obvious whether it should preserve existing exceptions or only avoid introducing new ones (it may be split in 2 options at some point). But in any case, that support is incomplete, both in the middle-end and the x86 back-end. My advice would be to write such sensitive code in an inline asm.