Aaron Franke
Aaron Franke

Reputation: 4092

How can I find math operations that would be optimized by `-ffast-math`?

The -ffast-math C++ compiler option allows the compiler to perform more math optimizations that may slightly change behavior. For example, x * 10 / 10 should cancel but due to the possibility of overflow it would slightly change behavior, and x / 10.0 / 10.0 may have different rounding errors than x / 100.0.

However, as many resources have noted, including many questions here on StackOverflow, the -ffast-math C++ compiler option can result in strange behavior across platforms. Instead, the recommended approach is to manually add parentheses around the operations you want the compiler to optimize.

Is there a way to identify these parts of the codebase? Some kind of static analysis tool that can find all lines of code that would be different if -ffast-math were enabled, so that the programmer can manually adjust those lines of code to be optimized even without -ffast-math enabled?

Upvotes: 5

Views: 194

Answers (0)

Related Questions