Not So Simple - The -fsimple Option
By rchrd on Jan 21, 2009
As mentioned earlier, the -fast compiler option is a good way to start because it is a combination of options that result in good execution performance.
But one of the options included in -fast is -fsimple=2. What does this do?
Unless directed to, the compiler does not attempt to simplify floating-point computations (the default is -fsimple=0). -fsimple=2 enables the optimizer to make aggressive simplifications with the understanding that this might cause some programs to produce slightly different results due to rounding effects.
Here's what the man page says:
Allow conservative simplifications. The resulting code does not strictly conform to IEEE 754, but numeric results of most programs are unchanged.
With -fsimple=1, the optimizer can assume the following:
IEEE 754 default rounding/trapping modes do not change after process initialization.
Computations producing no visible result other than potential floating point exceptions may be deleted.
Computations with NaNs (“Not a Number”) as operands need not propagate NaNs to their results; for example, x\*0 may be replaced by 0.
With -fsimple=1, the optimizer is not allowed to optimize completely without regard to roundoff or exceptions. In particular, a floating–point computation cannot be replaced by one that produces different results with rounding modes held constant at run time.
In addition to —fsimple=1, permit aggressive floating point optimizations. This can cause some programs to produce different numeric results due to changes in the way expressions are evaluated. In particular, the standard rule requiring compilers to honor explicit parentheses around subexpressions to control expression evaluation order may be broken with -fsimple=2. This could result in numerical rounding differences with programs that depend on this rule.
For example, with -fsimple=2, the compiler may evaluate C-(A-B) as (C-A)+B, breaking the standard’s rule about explicit parentheses, if the resulting code is better optimized. The compiler might also replace repeated computations of x/y with x\*z, where z=1/y is computed once and saved in a temporary, to eliminate the costly divide operations.
Programs that depend on particular properties of floating-point arithmetic should not be compiled with -fsimple=2.
Even with -fsimple=2, the optimizer still is not permitted to introduce a floating point exception in a program that otherwise produces none.
So if you use -fast, some programs that are numerically unstable might get different results than when not compiled with -fast. If this happens to your program, you can experiment by overriding the -fsimple=2 component of -fast by compiling with -fast -fsimple=0