Semantics of floating-point instructions are unclear

fadd etc. should follow IEEE754, with the following caveats:

  • As you’ve noticed, x87 has been broken since forever; the correct sequences aren’t obvious, it’s not clear how many people would take the performance penalty, and software built for targets without SSE2 is becoming increasingly rare. Other targets, including x86 targets with SSE2 enabled, shouldn’t be affected by this (except maybe m68k); the whole “long double register” thing was a failed experiment of the 80’s.
  • denormals are weird on certain targets (see LLVM Language Reference Manual — LLVM 17.0.0git documentation)
  • fast-math flags can change results, as you might expect
  • Messing with the floating-point environment isn’t allowed unless you’re using constrained intrinsics (LLVM Language Reference Manual — LLVM 17.0.0git documentation)