user1332148
user1332148

Reputation: 1346

What are the optimizations facilitated by -ffinite-math-only?

All the info I can find in documentation and the web for -ffinite-math-only is "Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs." This does not seem forthcoming to me. Does anyone know exactly what those optimizations are?

Upvotes: 5

Views: 1289

Answers (1)

Stephen Canon
Stephen Canon

Reputation: 106197

Lots of little things can be optimized under that assumption, like:

  • x == x --> 1
  • x * 1 --> x
  • x >= y --> !(x < y) and similar.
  • x/x --> 1 if the compiler can prove x != 0.
  • it may allow a compiler to use hardware max/min instructions for expressions like x > y ? x : y.
  • ... lots more

You often see this assumption together with assumptions like "sign of zero doesn't matter", which then allows things like:

  • x - x --> 0
  • 0 / x --> 0
  • x * 0 --> 0

Upvotes: 10

Related Questions