If the following C++ code is compiled with -fnon-call-exceptions, the tree optimisers still hoist 1.0 / 0.0:
--------------------------------------------------------- extern volatile int y; double foo (double a, int x) { while (x--) { y++; a += 1.0 / 0.0; } return a; } --------------------------------------------------------- Header copying ensures that 1.0 / 0.0 is only executed when the incoming x is nonzero, but the division happens before the assignment to "y". At -O, the hoisting is done by LIM; at -O2, it's done be PRE. -- Summary: Hoisting of potentially-throwing values for -fnon-call- exceptions Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rsandifo at gcc dot gnu dot org GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33615