Update the IRBuilder to generate constrained FP comparisons in CreateFCmp when IsFPConstrained is true, similar to the other places in the IRBuilder.
Also, add a new CreateFCmpS to emit signaling FP comparisons, and use it in clang where comparisons are supposed to be signaling (currently, only when emitting code for the <, <=, >, >= operators). Most other places are supposed to emit quiet comparisons, including the equality comparisons, the various builtins like isless, and uses of floating-point values in boolean contexts. A few places that I haven't touched may need some extra thought (e.g. are comparisons implicitly generated to implement sanitizer checks supposed to be signaling?).
I've noticed two potential problems while implementing this:
- There is currently no way to add fast-math flags to a constrained FP comparison, since this is implemented as an intrinsic call that returns a boolean type, and FMF are only allowed for calls returning a floating-point type. However, given the discussion around https://bugs.llvm.org/show_bug.cgi?id=42179, it seems that FCmp itself really shouldn't have any FMF either, so this is probably OK.
- Using builtins like __builtin_isless on a "float" type will implicitly convert the float argument to a double; apparently this is because the builtin is declared as having a variable argument list? In any case, that means that even though a quiet comparison is generated, the semantics still isn't correct for quiet NaNs, as that implicit conversion will already signal an exception. This probably needs to be fixed, but I guess that can be done as a separate patch.