[PATCH] D71467: [FPEnv] Generate constrained FP comparisons from clang

Ulrich Weigand via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 13 07:11:53 PST 2019


uweigand created this revision.
uweigand added reviewers: kpn, andrew.w.kaylor, craig.topper, cameron.mcinally, RKSimon, spatel, rjmccall, rsmith.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71467

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/fpconstrained-cmp.c
  llvm/include/llvm/IR/IRBuilder.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71467.233796.patch
Type: text/x-patch
Size: 14399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191213/bbd8ecb8/attachment-0001.bin>


More information about the cfe-commits mailing list