[PATCH] D62730: [RFC] Alternate implementation of D53157 IRBuilder for Constrained FP using enumeration vs MDNode and add support for fp-model and fp-speculation language options

Melanie Blower via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 06:56:52 PDT 2019


mibintc created this revision.
mibintc added reviewers: andrew.w.kaylor, kpn.
Herald added a subscriber: mgorny.
Herald added a project: LLVM.

This is part of RFC to support language options -fp-model and -fp-speculation.

This makes a small modification to D53157 <https://reviews.llvm.org/D53157> to pass some arguments using an enumeration type instead of MDNode.

In addition I created the FPState.h file which declares 2 enumeration types corresponding to the option settings.  I want to put them into llvm so it will be available not only to clang but to other language front ends that might want to offer floating point control using option settings.  The language options are combined using certain semantics into IRBuilder settings.  There's a member function in FPState.h that does this.

There's a clang patch that goes along with this patch.

Here's the RFC pasted from email to llvm-dev and clang-dev: 
Intel would like to contribute a patch to implement support for these Intel- and Microsoft -fp options:
-fp-model=[precise|strict|fast|except[-]] and -fp-speculation=[fast|strict|safe]

This contribution would dovetail with the llvm patch "Teach the IRBuilder about constrained fadd and friends" which is under review here, https://reviews.llvm.org/D53157/new/.  I have a patch ready to review that works with D53157 <https://reviews.llvm.org/D53157>.  The motivation for providing these is that having a single option to control most basic FP options is better and easier to understand for users.

The option settings -fp-model=[precise|strict|fast|except] are supported by both ICC and CL. The fp-speculation option is supported only by ICC.  The CL and ICC -fp-model option is documented on these pages:

  https://docs.microsoft.com/en-us/cpp/build/reference/fp-specify-floating-point-behavior?view=vs-2019
  https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-fp-model-fp

Currently, clang's default behavior corresponds to -fp-model=precise.  Clang/llvm support for -fp-model=[strict|except] is being developed in the D53157 <https://reviews.llvm.org/D53157> patch, and there is current llvm support for the fast settings by using the fast math flags llvm::FastMathFlags.  Note: the clang-cl wrapper to support Microsoft options has simplified support for these options by mapping /fp-model=except to ftrapping-math, fp-mdel=fast to ffast-math, fp-model=precise and fp-model=strict to fno-fast-math (see clang/Driver/CLCompatOptions.td).

According to the online options documentation, you can combine except[-] with [precise|strict|fast], but combining both fast and except is not a valid setting (the Driver will emit an error).

  precise - Disables optimizations that are not value-safe on floating-point data, although FP contraction is enabled.
  strict - Enables precise and except, disables contractions (FMA), and enables pragma stdc fenv_access.   
  fast - Equivalent to -ffast-math
  except/except- - Determines whether strict floating-point exception semantics are honored.

The ICC option -fp-speculation is described here,

  https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-fp-speculation-qfp-speculation

These are the meanings of the fp-speculation settings:

  fast - Tells the compiler to speculate on floating-point operations.  This is equivalent to “fpexcept.ignore” in the constrained intrinsics review D53157.
  strict - Tells the compiler to disable speculation on floating-point operations.  This is equivalent to “fpexcept.strict” in the constrained intrinsics review D53157.
  safe - Tells the compiler to disable speculation if there is a possibility that the speculation may cause a floating-point exception.  This is equivalent to “fpexcept.maytrap” in the constrained intrinsics review D53157.


Repository:
  rL LLVM

https://reviews.llvm.org/D62730

Files:
  include/llvm/IR/FPState.h
  include/llvm/IR/IRBuilder.h
  lib/IR/CMakeLists.txt
  lib/IR/FPState.cpp
  unittests/IR/IRBuilderTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62730.202425.patch
Type: text/x-patch
Size: 23480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190531/c5429245/attachment-0001.bin>


More information about the llvm-commits mailing list