[PATCH] D106191: [clang] Option control afn flag

Masoud Ataei via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 8 08:26:11 PDT 2021


masoud.ataei marked an inline comment as not done.
masoud.ataei added inline comments.


================
Comment at: clang/docs/UsersManual.rst:1393
+
+   Allow substitution of approximate calculations for functions.
+   Defaults to ``-fno-approx-func``.
----------------
erichkeane wrote:
> masoud.ataei wrote:
> > erichkeane wrote:
> > > This seems pretty incomplete to me, I have no idea what it does from this description.  Can you elaborate?
> > If I didn't miss to say it is about math function calls, then I guess it would be more clear. 
> > ```
> > Allow substitution of approximate calculations for math function calls.
> > ```
> > This option just adds `afn` fast-math flag to the function calls and in backend the math function call can be replaced by an approximate calculation (either another math function call or not). 
> > https://llvm.org/docs/LangRef.html#fast-math-flags
> allow substitution of approximate calculations for math function with what?  I'm not clear as to what this does still.  I'm not sure that I get what the 'afn' documentation means there either.  Typically we'd want the clang frontend flags to be more accurate/descriptive than the LLVM-IR documentation.
This option adds `afn` fast-math flag to function calls in IR. And in the case of math function calls (like `log`, `sqrt`, `pow`, ...), `afn` flag allows LLVM to substitute the math calls with an "approximate calculation". What an approximate calculation is may differ based on which math call it is, what other fast-math flags are set, what is the target machine, and other factors.

An approximate calculation can be
 1. sequence of instructions (inlining): for example, inlining sqrt call needs `afn` flag to be present in the call.
 2. a substituted math function call (which may be less accurate but faster): 
     this substitution can be 
     (a) for general targets: for example: `pow(x,0.25)` to `sqrt(sqrt(x))`. or
     (b) for a specific target: for example, in the case of PowerPC, we are proposing to substitute math calls to MASS library calls https://reviews.llvm.org/D101759

Note that, `afn` flag is necessary for these approximate calculation but may not be sufficient. Most of them need at lease one or two other fast-math flags to be set too. 

I agree the term "approximate calculation" is a very general term. But I guess it is needed to describe this general situation. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106191/new/

https://reviews.llvm.org/D106191



More information about the cfe-commits mailing list